Commit Graph

6754 Commits

Author SHA1 Message Date
Joe Groff
0eaea169d0 SILGen: Handle computed static properties.
Produce a metatype value to feed the 'self' argument of the accessor.

Swift SVN r10419
2013-11-13 16:45:42 +00:00
Doug Gregor
66b9f36ff5 When emitting sibling method calls, callect substitutions from all levels.
Previously, we were only looking at the innermost level, ignoring
outer generic types. Fixes the SILGen part of
<rdar://problem/15345742>, but IRGen issues remain.


Swift SVN r10418
2013-11-13 06:48:00 +00:00
Chris Lattner
425819ac07 Change the SIL string_literal instruction to produce three results
(the same way alloc_box returns two) instead of returning a tuple.

This eliminates a ton of tuple_extract instructions, which just
bloat the generated SIL.  This resolves rdar://15378135.



Swift SVN r10416
2013-11-13 06:43:09 +00:00
Doug Gregor
50cb22b6da Teach Builtin.castToObjectPointer to handle class-bounded existentials.
Fixes <rdar://problem/15258208>.


Swift SVN r10397
2013-11-13 00:35:02 +00:00
Joe Groff
19f1bbdebb SILGen: Emit global initialization for static properties.
For the subset of static properties we're implementing, we can skate by with global static constructors like we do for global variables. Leave some asserts behind so we revisit this when we implement the hard cases.

Swift SVN r10383
2013-11-12 23:27:47 +00:00
Joe Groff
c1f34728e2 SILGen: Release re-abstracted value on 'default' branch of 'is T' pattern match.
Now that the stack allocation for an abstraction change is in a predictable place, we can cleanly deallocate it at the end of dispatch. Fixes <rdar://14835992>.

Swift SVN r10024
2013-11-07 16:27:49 +00:00
Joe Groff
2a4dfed8f5 SILGen: Emit RawRepresentable methods of imported enums.
In SILGen, when we emit the enum external definition, emit the methods in addition to the case constructors for the enum. Make sure they get thunk linkage.

Swift SVN r10017
2013-11-07 03:49:32 +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
Joe Groff
6f519d7b6f SILGen: Emit enum constructors for Clang-imported enums.
Swift SVN r9990
2013-11-06 06:31:26 +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
Anna Zaks
54524e622a Replace ExprStmtOrDecl with ASTNode and make it a struct.
Previously, the Parser and BranchStmt typedef-ed ExprStmtOrDecl as a pointer union. Using typedef made the objects compatible, but did not allow us to extend the type with helper methods, such as getSourceRange(), which is something you can get on all of the AST objects. This patch introduces ASTNode that subclasses from PointerUnion and is used by both parser and BranchStmt.

Swift SVN r9971
2013-11-05 21:46:59 +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
Anna Zaks
16774496fd [SILGen] Emit warnings when SILGen fails to emit unreachable code.
Previously, we just did not emit SIL for unreachable code from these examples.

Swift SVN r9949
2013-11-05 01:17:14 +00:00
Joe Groff
1616276923 SILGen: Remove 'SILGenLValuePeepholes' flag.
r9931 fixes the crashes this exposes, so we can enable it by default now.

Swift SVN r9935
2013-11-04 22:54:54 +00:00
Joe Groff
18dd9335f3 SILGen: Factor abstraction change from branch in checked cast emission.
<rdar://problem/14835992> happens because, when we emitted a chain of checked casts for 'is' patterns in a 'switch', we would emit abstraction changes for each individual cast that required them. This is both redundant and makes cleaning up messier, because the number of branches with different stack heights increases. Instead, let's emit one abstraction change up front for all of the casts. No functionality change yet, but this is a step on the way to fixing <rdar://problem/14835992>.

Swift SVN r9921
2013-11-04 17:44:03 +00:00
Chris Lattner
f959378aa3 revert my previous patch. It doesn't break anything, but there is more going on
here than I think I understand, so I'm backing off.


Swift SVN r9909
2013-11-03 18:46:10 +00:00
Chris Lattner
aa4d91972c remove some peephole logic that is trying to turn a copyaddr into its component
parts.  Our canonical representation is going towards more complex operations
now, so this isn't useful.


Swift SVN r9908
2013-11-03 18:41:12 +00:00
Chris Lattner
68af974227 Remove 'axle' related code and build machinery. It turns out that we
will not be pursuing this project in the immediate future.



Swift SVN r9901
2013-11-03 16:04:27 +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
Joe Groff
5744b57e8f SILGen: Handle an 'is T' pattern in a switch that introduces concrete-to-archetype casts.
When destructuring the 'is Int' pattern in:

func f<T, U>(t: T, u: U) {
  switch t {
    case is Int: println("Int")
    case is U: println("U")
    case _: println("other")
  }
}

there is the possibility that 'U' is 'Int', so it needs to be included in the specialization on 'is Int' using a concrete-to-archetype cast from Int to U. This wasn't handled correctly and we tried to do a super-to-archetype class cast instead, which blew up because 'Int' is neither a class nor statically related to U. Fixes <rdar://problem/14826416>.

Swift SVN r9869
2013-11-01 15:23:46 +00:00
Joe Groff
003709d51f SIL: Add a backreference from SILModule to its originating Swift Module.
Ideally this wouldn't be necessary, but the type substitution APIs required by generic specialization and SIL verification currently require a Module* pointer, and it's obnoxious to have to pass it down separately everywhere it's needed. Longer-term the reliance on Modules for type substitution might be able to go away.

Swift SVN r9866
2013-11-01 00:46:21 +00:00
Joe Groff
c57ea38b95 SILGen: Don't produce context arguments for captured typealiases.
If a local function tried to reference a local typealias, we were trying to emit a SIL variable reference and freaking out, causing <rdar://problem/15360605>. For now, don't emit any capture arguments for local typealiases. Any context a local typealias requires should be handled by capturing the external context's generic parameters.

Swift SVN r9865
2013-11-01 00:12:29 +00:00
Joe Groff
5ec3cad5f6 ClangImporter: Emit metadata for imported enums.
Whatever kind of Swift decl we cons up for a Clang enum, add it to the externals list so we can pick it up and emit Swift metadata for it in IRGen. Fixes <rdar://problem/15242452>.

Swift SVN r9801
2013-10-30 18:15:09 +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
Joe Groff
1ff79ff951 SILGen: Fix use-after-free in 'x?' codegen.
Forward the result before closing the scope so it's still good when we pass it on out of the optional evaluation.

Swift SVN r9773
2013-10-30 00:17:34 +00:00
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
82184a60b9 s/addSubstitutions/setSubstitutions
Swift SVN r9723
2013-10-28 20:37:13 +00:00
Doug Gregor
55bcdedd5d Replace substitutions vector with an ArrayRef, now that we have only one level.
Swift SVN r9722
2013-10-28 20:35: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
Doug Gregor
731fe651e7 Teach OtherConstructorDeclRefExpr to track substitutions.
Eliminates another source of SpecializeExprs.


Swift SVN r9714
2013-10-28 18:35:49 +00:00
Chris Lattner
cff509767f fix 80 column violations
Swift SVN r9704
2013-10-28 00:36:23 +00:00
Chris Lattner
5ce1700021 - Mark the copyaddr's generated for inout shadow variables as autogenerated,
so they can be easily identified by the inout deshadowing pass.  This does
  not mark the alloc_box as autogenerated though, since it is a user variable
  when the variable escapes.

- Fix some wonky indentation in SILLocation.



Swift SVN r9700
2013-10-27 22:48:05 +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
Adrian Prantl
5bbe0afb9f Debug info: Properly handle the function prologue in the line table.
Introduces a new flag in SILLocation: InPrologue to mark instructions
that setup the stack and allocate storage for local variables/arguments.

Fixes rdar://problem/15290023: Breakpoint set on prologue - crash ensues.

Swift SVN r9686
2013-10-26 00:12:20 +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
Jordan Rose
28e01f3c3a Eliminate "MainSourceFile" from TranslationUnit in favor of an array.
Anywhere that assumes a single input file per TU now has to do so explicitly.
Parsing still puts all files in a single SourceFile instance; that's next on
the list.

There are a lot of issues still to go, but the design is now in place.

Swift SVN r9669
2013-10-25 17:30:37 +00:00
Doug Gregor
8ea71f06a7 Teach ExistentialMemberRefExpr to handle all levels of substitutions.
Another SpecializeExpr usage bites the dust.


Swift SVN r9665
2013-10-25 00:02:36 +00:00
Doug Gregor
10164fa56c Teach ArchetypeMemberRefExpr to handle all levels of substitutions.
Eliminates another source of SpecializeExprs.


Swift SVN r9655
2013-10-24 21:44:45 +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
Doug Gregor
905078a278 Open method references via the interface type rather than the polymorphic type.
Once we've opened method references via the interface type, we then
fold all levels of generic argument specialization into the
DeclRefExpr, rather than using SpecializeExpr. For reference, the call
to x.f in this example:

struct X<T> {
  func f<U>(u : U) { }
}

func honk(x: X<Int>) {
  x.f("hello")
}

goes from this double-specialized AST:

        (specialize_expr implicit type='(u: String) -> ()'
          (with U = String)
          (dot_syntax_call_expr type='<U> (u: U) -> ()'
            (specialize_expr implicit 
               type='(@inout X<Int>) -> <U> (u: U) -> ()'
              (with T = Int)
              (declref_expr type='<T> @inout X<T> -> <U> (u: U) -> ()'
        decl=t.X.f@t.swift:2:8 specialized=no))

to the cleaner, SpecalizeExpr-free:

        (dot_syntax_call_expr type='(u: String) -> ()'
          (declref_expr type='(@inout X<Int>) -> (u: String) -> ()'
            decl=t.X.f@t.swift:2:8 [with T=Int, U=String]
            specialized=no)

which handles substitutions at both levels together. The minor SILGen
tweak 

Note that there are numerous other places where we are still generated
SpecializeExprs.


Swift SVN r9614
2013-10-23 05:35:16 +00:00
Joe Groff
db5fe95abb AST: Add a Builtin.condfail function.
Lowered by SILGen into a cond_fail instruction.

Swift SVN r9591
2013-10-22 15:53:11 +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
Dmitri Hrybenko
acdd5b120a Make type checker debug output redirectable
Introduce a replaceable TypeCheckerDebugConsumer for this.


Swift SVN r9555
2013-10-21 20:26:32 +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
Joe Groff
d3fd8292ff SILGenPattern: Let 'is T' and 'U(x:, y:)' patterns coexist.
When destructuring a NominalTypePattern, keep the aggregate around as an extra column of the destructured matrix so we can still match non-NominalTypePatterns against it. This handles 'is T' patterns on the same type, and should also handle other fancy high-level patterns we might add in the future.

Swift SVN r9538
2013-10-21 15:25:01 +00:00
Joe Groff
4bc267f716 SILGenPattern: Don't drop preceding wildcard rows when specializing a column.
Other columns may have significant patterns.

Swift SVN r9537
2013-10-21 15:24:57 +00:00
Joe Groff
4872a6fc7b SILGen: Use "constructor prefix" heuristic to optimize switch decision trees.
According to Maranget this heuristic gave the best results over a large corpus of Ocaml code. Luckily, it's really easy to implement too—just count through each column until we hit a wildcard, and specialize on the column with the most non-wildcard pattern nodes before a wildcard.

Swift SVN r9533
2013-10-21 03:57:32 +00:00
Joe Groff
98a78306fc SILGen: Run cleanups emitted as a part of pattern dispatch.
Fixes the issue with address-only struct patterns.

Swift SVN r9527
2013-10-20 17:16:27 +00:00