Commit Graph

1613 Commits

Author SHA1 Message Date
Anna Zaks
e5eb77ea6e [SIL] Mark these locations as cleanup.
The empty tuple used for return value when none is supplied does not really correspond to user code. (We don’t have epilog, so mark it as pert of cleanup.)
The destroy_addr instructions are doing the cleanup.

Swift SVN r9765
2013-10-29 22:27:25 +00:00
Doug Gregor
112c6123eb Terminate SpecializeExpr with extreme prejudice.
There are numerous other cleanups that could be performed now that
this is gone; I'll follow up with some of them.


Swift SVN r9717
2013-10-28 18:50:29 +00:00
Dmitri Hrybenko
b62e8903de Portability: libstdc++ does not implement is_trivially_copyable yet, implement
our own wrapper


Swift SVN r9695
2013-10-27 05:52:22 +00:00
Jordan Rose
64e0b2200a Make sure to resolve library intrinsics before using them.
Otherwise, compiling the standard library will try to use, say,
_getOptionalValue() before that function has any type.

Swift SVN r9671
2013-10-25 17:30:41 +00:00
Dmitri Hrybenko
80d753d0ab Portability: use std::make_tuple instead of relying on a libc++ extension (an
implicit constructor in std::tuple)


Swift SVN r9615
2013-10-23 06:17:28 +00:00
Joe Groff
3a5267c020 SILGen: Build a thunk in SILGen instead of using convert_cc instruction.
We already know how to call external functions in SILGen, why reimplement all that in IRGen? Instead of representing the thunk operation as a SIL instruction, let's just emit the thunk using existing SILGen machinery. Fixes <rdar://problem/14097136>.

Swift SVN r9576
2013-10-22 03:16:15 +00:00
Joe Groff
86481263ac SILGen: Remove some debug noise.
Swift SVN r9570
2013-10-21 23:33:20 +00:00
Joe Groff
0da9261182 SILGen: Thunk Clang-imported top-level functions when used unapplied as values.
And tweak the verifier to allow 'convert_cc' over a static FunctionRefInst to remain thin. The SILGen part of <rdar://problem/14097136>.

Swift SVN r9556
2013-10-21 20:39:57 +00:00
Doug Gregor
5521b53382 Use DeclRefExpr's substitutions rather than SpecializeExpr for free functions.
Rather than wrapping a DeclRefExpr in a SpecializeExpr for a reference
to a generic free function, just use the substitutions stored within
the DeclRefEXpr. Such DeclRefExprs will always have a concrete
type. One tiny nail in the SpecializeExpr coffin.


Swift SVN r9539
2013-10-21 15:39:56 +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
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
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
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
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
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
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
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
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
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
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
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
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
Joe Groff
a2672e9313 SIL: Turn conditional checked casts into a branch instruction.
Replace the existing suite of checked cast instructions with:

- unconditional_checked_cast, which performs an unconditional cast that aborts on failure (like the former downcast unconditional); and
- checked_cast_br, which performs a conditional pass and branches on whether the cast succeeds, passing the result to the true branch as an argument.

Both instructions take a CheckedCastKind that discriminates the different casting modes formerly discriminated by instruction type. This eliminates a source of null references in SIL and eliminates null SIL addresses completely.

Swift SVN r8696
2013-09-26 18:24:44 +00:00
Joe Groff
cbfe3710f6 SIL: Rename the 'isObjC' SILDeclRef specifier to 'isForeign'.
Doug pointed out that 'isObjC' incorrectly excludes C functions, for which we'll also need to be able to independently reference Swift and foreign entries.

Swift SVN r8669
2013-09-25 21:59:03 +00:00
Joe Groff
3d4c1251f1 Rename 'byref' attribute to 'inout'.
Swift SVN r8661
2013-09-25 20:56:52 +00:00
Joe Groff
8f585557ca SIL: Fully capture byref shadow copy boxes.
Remove 'Byref' as a separate CaptureKind, and always capture the full box for all variables.

Swift SVN r8633
2013-09-25 18:41:50 +00:00
Doug Gregor
b8daa3c68d SIL generation for dynamic subscript expressions.
Re-instates r8591 with rather more sensible generated SIL.


Swift SVN r8599
2013-09-24 20:08:19 +00:00
Doug Gregor
e3b50c207c Back out r8591; it's going to take me a bit longer to fix.
Swift SVN r8596
2013-09-24 18:56:09 +00:00
Doug Gregor
fdd5ebd342 SIL generation for dynamic subscript expressions.
No IRGen testing yet because the recently-introduced [objc] subscript
thunks (r8587) can't be IRGen'd properly yet.



Swift SVN r8593
2013-09-24 14:48:51 +00:00
Doug Gregor
f67aa78d69 Dynamic lookup for subscripts: semantic analysis and ASTs.
Swift SVN r8591
2013-09-24 05:51:30 +00:00
John McCall
22a3574654 Use copy_value and destroy_value when destroying loadable
aggregates in SIL-gen.  Leave the old expanded paths around
as emitLoweredCopyValue and emitLoweredDestroyValue.

Swift SVN r8535
2013-09-20 23:33:40 +00:00
Dmitri Hrybenko
429633b18a Let the type checker create implicit DestructorDecls
Improve the type checker to create implicit DestructorDecls, tighten the
assertion in ImplicitReturnLocation::getImplicitReturnLoc(), and add a verifier
check that a class in a type checked AST always has exactly one destructor.

SILGen used to generate a destructor if the class does not have a
DestructorDecl.  SILGen used to put the ClassDecl inside the SILLocation for
the destructor SIL code.  This is not a very clean solution: in this case
ImplicitReturnLocation SILLocations contain ClassDecl, which is surprising.

rdar://14970972 Implicit destructors should have AST nodes


Swift SVN r8498
2013-09-20 17:34:22 +00:00
Joe Groff
e109124186 Replace 'union' keyword with 'enum'.
This only touches the compiler and tests. Doc updates to follow.

Swift SVN r8478
2013-09-20 01:33:14 +00:00
Doug Gregor
bcf5345626 Eliminate the completely-broken implicit default constructor for classes.
When a given class definition has no constructors, the parser was
introducing an implicit-declared default constructor in the class. The
type checker ignored it. SILGen creating something that was completely
broken. Remove all of that and fix the fallout.




Swift SVN r8432
2013-09-18 23:58:34 +00:00
Joe Groff
fd1e1c55bd SILGen: Don't pass down stale stack values from address-only ternaries.
When emitting ternaries of address-only type we were providing a result address that pointed into dead stack storage. Oops.

Swift SVN r8422
2013-09-18 22:11:11 +00:00
Doug Gregor
18f9420bcb Stop generating definitions for the imported initializing constructors.
When we import an Objective-C init method into Swift as a constructor,
the Clang importer currently synthesizes both a +alloc call (used by
the allocating constructor) and a body that forwards to the
corresponding init method. Eliminate the body and stop emitting an
initializing constructor at all: instead, the allocating constructor
will invoke the init method through objc_msgSend.



Swift SVN r8420
2013-09-18 21:35:38 +00:00
Doug Gregor
90b8b3e499 Constructor selectors always start with 'init'.
Implement the new rules for mapping between selector names and
constructors. The selector for a given constructor is formed by
looking at the names of the constructor parameters:
  * For the first parameter, prepend "init" to the parameter name and
  uppercase the first letter of the parameter name. Append ':' if
  there are > 1 parameters or the parameter has non-empty-tuple type.
  * For the remaining parameters, the name of each parameter followed
  by ':'.

When a parameter doesn't exist, assume that the parameter name is the
empty string.

And, because I failed to commit it separately, support selector-style
declarations of constructor parameters so that we can actually write
constructors nicely, e.g.:

  // selector is initWithFoo:bar:
  constructor withFoo(foo : Foo) bar(bar : Bar) { ... }



Swift SVN r8361
2013-09-17 22:49:05 +00:00