Commit Graph

9332 Commits

Author SHA1 Message Date
Manman Ren
61d547a2a1 SIL Parser: handle SIL functions with generic params and parse archetype_method.
Construct ArchetypeType from generic params; Construct a Scope for the SIL
function body so TypeAliasDecl for the generic params can be added to ScopeInfo.
Remove an extra '$' in SILPrinter when printing the lookup type for an
archetype_method.


Swift SVN r6219
2013-07-12 22:21:14 +00:00
Joe Groff
185399787d SILGen: Reenable 'fallthrough'.
Reimplement fallthrough using switch's new internal representation of case-to-BB mappings and scope management. Fallthrough can't pass control into a case block with pattern variables, so fallthrough destinations will always be at outermost switch scope, and we can assume the destination block will be emitted in that scope.

Swift SVN r6197
2013-07-12 01:23:46 +00:00
Joe Groff
ef60e04e27 SILGen: Don't rescope cases unless they actually bind variables in a specialization.
Check that a row in the clause matrix actually binds variables before rescoping it during pattern specialization, instead of always rescoping it if its constructor got specialized. We need to be able to `fallthrough` into scopes without variables, and fallthrough-ing across scopes isn't going to work. A nice side effect of this is that we can kill some useless continuation BBs; we won't use the continuation BB for a specialization scope unless variables actually get bound in that scope.

Swift SVN r6191
2013-07-12 00:07:23 +00:00
Jordan Rose
e3999dde36 [serialization] Handle absent protocol conformances.
These still need to be serialized, because they are one-to-one with the
type's protocol list, but don't actually require any data. Found on
attempting to emit a module for the standard library.

Most of the churn here is moving Interleave.h to a more general STLExtras.h.

Swift SVN r6167
2013-07-11 18:38:50 +00:00
Anna Zaks
4078785192 Turn SILLocation out of typedef and into a class.
Swift SVN r6154
2013-07-11 17:12:13 +00:00
Anna Zaks
2e4170e249 Add the first SIL-based waring - "missing return"
Add a warning on a missing return statement.
(This is not yet an error since we need to handle no-return functions.)

Swift SVN r6153
2013-07-11 17:12:12 +00:00
Anna Zaks
c315b357af Add SILLocation to the SILFunction and to the UnreachableInst, which represents falling off the end of the function.
Both of these are needed to produce user-friendly diagnostics from SIL.

Swift SVN r6152
2013-07-11 17:12:12 +00:00
Anna Zaks
85ff034a1f Move isVoid() helper from SILGen to Types.
Swift SVN r6151
2013-07-11 17:12:10 +00:00
Joe Groff
1080533095 SILGen: Emit case bodies in their appropriate scopes.
I was emitting cases in the wrong scopes, causing control flow transfers inside the case body to over-release. Oops. Fix that by emitting case bodies last thing before closing out a scope instead of trying to do them on demand.

Swift SVN r6145
2013-07-11 02:54:12 +00:00
Dmitri Hrybenko
7dcbba722e Silence an "unused variable" warning in NDEBUG build
Swift SVN r6139
2013-07-10 23:32:02 +00:00
Joe Groff
f24add3175 SIL: Give Unreachable instructions SILLocation info.
UnreachableInst's constructor didn't take a SILLocation. Oops. Fix that, and associate Unreachables emitted due to failed switch coverage with the switch. For missing-return Unreachables, there isn't yet readily available SILLocation info to attach to them, but Anna will fix that soon.

Swift SVN r6132
2013-07-10 21:54:37 +00:00
Joe Groff
4bbf608e8f SILGen: Implement variable bindings.
As clause matrix specialization exposes columns with variable bindings, bind all of the variables in each column to a new box for the variables in that column. (Since only one row out of the matrix ever ends up getting executed, we can share one box for the entire column.) Set up a scope hierarchy following that of the specialized clause matrices, and associate each case with the scope it needs to see all the variables of its fully-destructured pattern clause. Remove our ad-hoc hack for binding ExprPattern implicit variables, and bind them to the column's box too.

Swift SVN r6127
2013-07-10 19:09:58 +00:00
Argyrios Kyrtzidis
a70eff6609 Introduce TypeRepr and related subclasses, that is a representation of a type as written in source.
This the first part for improving source location fidelity for types,
changes to follow:

-The Parser will not create any types, it will just create TypeReprs.
-The type checker will create the types by going through TypeReprs.
-IdentifierType will be removed.

Swift SVN r6112
2013-07-10 14:58:52 +00:00
John McCall
87ef9204d4 Rewrite the storage type of a [weak] or [unowned] variable.
getTypeOfReference drops the ReferenceStorageType from the
variable when it introduces the LValueType.

Swift SVN r6110
2013-07-10 07:56:38 +00:00
Dmitri Hrybenko
92523fbb8f Silence unused variable warnings in NDEBUG builds
Swift SVN r6097
2013-07-09 22:35:01 +00:00
Joe Groff
5f9ff68d95 Revert r5949: "SIL: Null-terminate literal instruction string data."
The APFloat crash should be fixed in LLVM trunk, and we haven't seen the Interpreter crash in a while.

Swift SVN r6095
2013-07-09 20:49:52 +00:00
Joe Groff
378d2b3672 SILGen: Emit case block BBs as part of dispatch.
Put emitDecisionTree in charge of setting up case-to-BB mappings as they are needed by leaves of the decision tree. This lets us avoid emitting empty waypoint BBs for default dispatches, cull unreachable case blocks, and will let us handle the scoping of pattern variables relative to case blocks. This new implementation breaks fallthrough, but it's going to need reworking in the face of case variables anyway, so tear out the old implementation and mark it as not implemented for now.

Swift SVN r6094
2013-07-09 17:02:38 +00:00
John McCall
18a9290cbe Add ReferenceStorageType.
The idea for now is that this is a SIL-only type used for
representing the storage of a weak or unowned reference.
Having it be its own type is pretty vital for reasonable
behavior in SIL and IR-generation, and it's likely that
this will surface into runtime metadata as well (hence
the mangling).

I've implemented a bunch of things that technically I don't
think are necessary if this stays out of the typechecker,
but it's easier to implement half-a-dozen "recurse into
the child type" methods now that it would be to find them
all later if we change our minds.

Swift SVN r6091
2013-07-09 08:37:40 +00:00
Joe Groff
da241e645e SILGen: Eliminate PatternConstructor intermediate representation.
We can figure out the orthogonality, specialization, and dispatch behavior we need using Pattern AST nodes directly. And because we need logic more complex than equality comparison to deal with pattern specialization on type casts, the canonicalization to an abstract pattern constructor form doesn't really save us enough to be worth having another "thing" around.

Swift SVN r6082
2013-07-09 00:02:22 +00:00
Joe Groff
6d4d0ee629 SILGen: Fix typo.
Swift SVN r6061
2013-07-08 20:21:20 +00:00
Joe Groff
666be0ff4a SILGen: Match 'is' patterns.
Casts to concrete struct types are orthogonal to each other, so when we see one or more "is S" patterns in a switch, we can specialize the clause matrix on each of those types. Casts to class types and casts to or from archetypes are a bit trickier since they don't necessarily refute other types, so our ability to specialize on those cases is limited. With type relationship information, we could refute casts to unrelated classes or concrete types, but that data doesn't survive type-checking right now. For now, when we specialize on a class or archetype cast, conservatively preserve casts to all other classes or concrete types. In the class case, a class cast is at least able to refute non-class casts.

Swift SVN r6057
2013-07-08 18:42:09 +00:00
Manman Ren
a63c78b81a SIL Parser: parse protocol_method.
New format for SILConstant:
  '#' sil-dotted-path sil-constant-kind-and-uncurry-level?
  sil-dotted-path:
    identifier ('.' identifier)*
  sil-constant-kind-and-uncurry-level:
    '!' sil-constant-kind ('.' sil-constant-uncurry-level)? ('.objc')?
    '!' sil-constant-uncurry-level ('.objc')?
    '!objc'
  sil-constant-kind:
    'func' | 'getter' | 'setter' | 'allocator' | 'initializer' | 'oneofelt' \
    | 'destroyer' | 'globalaccessor'

Add helper function printFullContext in SILPrinter to generate the fully
qualified dotted path for a given DeclContext; Add parseSILConstant to
SILParser; Testing cases are updated to reflect the new format.


Swift SVN r6055
2013-07-08 18:24:15 +00:00
Jordan Rose
d8414ee000 Remove suspicious assertion in SIL/TypeLowering.cpp.
I checked with Joe and he said he can't figure out what it was going for;
it's almost certainly not correct as is.

Swift SVN r6031
2013-07-06 00:20:01 +00:00
Joe Groff
a5a64fcd96 SILGen: Elide rows prior to a pattern ctor's first specialization.
Since pattern matches semantically occur in source order, we need to exclude rows prior to the first occurrence of a pattern constructor when producing the specialized clause matrix for that constructor. This falls out naturally for constructors that are orthogonal, such as oneof alternatives, but will be required for 'is' patterns, where specializations can overlap due to subtype relationships, as in:

class B {}
class D : B {}

var b:B
var x:Int

switch (b, x) {
case (is B, 0):
  foo()
case (is D, 1):
  bar()
case (is B, 2):
  bas()
}

The 'is D' specialization needs to exclude the first 'is B' pattern.

Swift SVN r6028
2013-07-05 23:11:34 +00:00
Doug Gregor
2c49592c3a Mangle declarations imported from Clang with the context SC.
Fixes <rdar://problem/14221244>.


Swift SVN r6022
2013-07-05 22:08:57 +00:00
Joe Groff
ea20a3bfb8 SILGen: Match ExprPatterns.
ExprPatterns are essentially guards. When exploring the clause matrix we treat the ExprPattern itself as a wildcard, and as we expose leaf ExprPatterns, project their 'expr ~= value' conditions out on the row's guard.

Swift SVN r5997
2013-07-04 23:02:10 +00:00
Joe Groff
336a3c26ef SILGen: Match switches with tuples, wildcard patterns, and guards.
Lay the groundwork for the pattern matching compilation algorithm from Luc Maranget's "Compiling Pattern Matching to Good Decision Trees". This algorithm organizes the set of patterns to consider into a "clause matrix", where each row corresponds to a pattern and its branch destination, and each column is a destructured subelement of the pattern. The algorithm heuristically chooses a "necessary column"  on which to reduce the matrix; for that column, specialized matrices are generated for each constructor form in the column, which are then recursively considered until we reach a termination case where a matrix either has no rows, in which case the match fails, or a matrix's top row always succeeds, in which case we emit a leaf branch to that target.

For this initial version, we stick only to matching tuples and wildcards in naive left-to-right order. We modify the algorithm from the paper to also handle guards: if the first row in the clause matrix is all wildcards, then instead of unconditionally branching to the destination, we evaluate the guard and conditionally branch to the target; on the false branch, we proceed with Maranget's algorithm by removing the guarded row from the matrix.

We don't yet implement variable bindings, ExprPatterns, "is" patterns, or nominal type patterns.

Swift SVN r5993
2013-07-04 02:38:51 +00:00
Doug Gregor
4239e3db85 Mangle all Clang module contexts as "5__C__".
This partly rolls back <rdar://problem/14221244>, which caused the
ListMaker build to break. We need to mirror the Clang module structure
properly into Swift to actually get entities mangling into the right
contexts.


Swift SVN r5968
2013-07-03 16:49:53 +00:00
Joe Groff
0ac8c2b532 SIL: Null-terminate literal instruction string data.
Guard against StringRef-uncleanness in APFloat (e.g. rdar://14323230) and hopefully stop the intermittent buildbot failures in some Interpreter tests.

Swift SVN r5951
2013-07-01 21:48:31 +00:00
Chris Lattner
dc702b2be5 implement sil parser support for the rest of the unchecked conversion instructions.
Swift SVN r5942
2013-07-01 18:50:37 +00:00
Chris Lattner
77848dada1 Don't rely on overload resolution to find the right printing logic,
just make things explicit.  No functionality change.


Swift SVN r5932
2013-07-01 17:35:48 +00:00
Chris Lattner
6b4d262d24 silprint the type of the operand to checked conversions, improving parsability.
Swift SVN r5929
2013-07-01 17:18:50 +00:00
Chris Lattner
41591909d8 Change the syntax of SIL cast instructions to use the 'to' keyword.
This is better for uniformity with store and also is less of a punctuation
soup, making things easier to read.


Swift SVN r5928
2013-07-01 16:51:02 +00:00
Chris Lattner
6c4b37fd30 make class_method and protocol_method print the type of the object value being referenced,
a step towards parsability.


Swift SVN r5925
2013-07-01 16:31:39 +00:00
Chris Lattner
efaf4f6aee make the conversion instructions print the type of both the source and destination, so we can parse them.
Swift SVN r5918
2013-07-01 00:31:10 +00:00
Chris Lattner
5ac61b6b90 add testcase for unconditional branch, which exposes a bug: the wrong mneumonic was used.
Swift SVN r5915
2013-06-30 23:37:12 +00:00
Chris Lattner
9e5e077491 implement the "when expanded from a default argument context, use the location
of the call, not the magic identifier" semantics, completing rdar://14315674


Swift SVN r5914
2013-06-30 21:37:40 +00:00
Chris Lattner
2fe98e14e7 implement basic __FILE__, __LINE__, and __COLUMN__ magic identifiers.
Swift SVN r5912
2013-06-30 21:19:32 +00:00
Joe Groff
ce77714ae8 SILGen: Raise an error when cast*ObjectPointer are used incorrectly.
Instead of stampeding forward generating bogus SIL, raise an error and bail if cast*ObjectPointer are used with non-class values. Fix a test that was applying cast*ObjectPointer to things that were already ObjectPointers.

Swift SVN r5860
2013-06-27 23:48:54 +00:00
Joe Groff
9b1fa476b8 SIL: include function name in verifier failures.
Swift SVN r5857
2013-06-27 23:16:07 +00:00
Joe Groff
9d4328380a Mangle: Always mangle decl contexts.
Our mangling grammar says that entities should always be mangled with a context, so in cases where we weren't (Clang module contexts and top-level code), do so. Additionally, for ObjC protocols, mangle them into the special "So" context so we can catch global ObjC runtime namespace collisions with them. Fixes <rdar://problem/14221244>.

Swift SVN r5851
2013-06-27 23:07:06 +00:00
Adrian Prantl
de32b201d0 Debug Info: Add support for subprograms.
This means that single-stepping in lldb actually works now!

Swift SVN r5828
2013-06-27 00:46:30 +00:00
Doug Gregor
9a5c96a8c1 Introduce basic support for LLVM vectors as builtins.
This adds builtin types Builtin.VecNxT, where N is a natural number
and T is a builtin type, which map down to the LLVM type <N x T>. 

Update varous builtins to support vector arguments, e.g., binary
operations, comparisons, negation. Add InsertElement and
ExtractElement builtins for vectors.

On top of these builtins, add Vec4f and Vec4b structs to the standard
library, which provide 4xFloat and 4xBool vectors, respectively, with
basic support for arithmetic. These are mostly straw men, to be burned
down at our leisure.

Some issues as yet unresolved:
  - Comparisons of Vec4f'ss are producing bogus Vec4b's, which I
  haven't tracked down yet.
  - We still don't support the shuffle builtin, although it should be
  easy
  - More testing!



Swift SVN r5820
2013-06-26 21:16:36 +00:00
Joe Groff
59e803ed84 ClangImporter,SIL: Bridge ObjCBool to Bool.
Map BOOL parameters, return types, and properties to swift.Bool in the Clang importer like we map NSString to swift.String. Generalize SIL's handling of type bridging to accommodate Bool bridging in addition to String bridging. Add convertObjCBoolToBool and v.v. entry points for the compiler to use to insert bridging conversions between the two types. Implements <rdar://problem/14271667>.

Swift SVN r5819
2013-06-26 21:15:17 +00:00
Joe Groff
e460a01af6 Remove the 'UnresolvedCallPattern' I stubbed out.
I talked to John about parsing patterns today, and because of the magnitude of name-lookup-dependent ambiguities between patterns and expressions, we agreed that at least for a first-pass implementation it makes sense to parse patterns as extensions of the expr grammar and charge name binding with distinguishing patterns from expressions. This gets us out of needing the concept of an "unresolved pattern", at least in the short term.

Swift SVN r5808
2013-06-26 04:23:47 +00:00
Doug Gregor
cace751e86 Eliminate DeducibleGenericParamType.
The type was used by the old type coercion code; it is no longer relevant.


Swift SVN r5799
2013-06-25 16:32:44 +00:00
Joe Groff
8deec52b17 Rework AST representation of CaseStmts.
A single case block can have one or more 'case ...:' labels. 'case' labels contain patterns instead of exprs. 'default:' is a funny spelling for 'case _:'. Change the CaseStmt representation and rip out all the parsing, type-checking, and SILGen built off the old representation.

Swift SVN r5795
2013-06-25 00:31:42 +00:00
Dmitri Hrybenko
05203f70f3 ClangImporter: Use ConstDeclVisitor and constify Clang's decls throughout the importer
Swift SVN r5788
2013-06-24 20:27:57 +00:00
Adrian Prantl
fb7e2c0524 Remove superfluous virtual keyword as pointed out by Joe's review.
Swift SVN r5784
2013-06-24 18:40:27 +00:00
Joe Groff
7ba95cfd26 Add AST nodes for refutable patterns.
Introduce Pattern subclasses for the 'is T', 'T(<pattern>)', and '<expr>' pattern syntaxes we'll be introducing for pattern-matching "switch" statements. Also add an 'UnresolvedCalLPattern' to act as an intermediate for name lookup to resolve to a nominal type, oneof element, or function call expression pattern. Since we'll need to be able to rewrite patterns like we do expressions, add setters to AST nodes that contain references to subpatterns. Implement some basic walking logic in places we search patterns for var decls, but punt on any more complex type-checking or SILGen derived from these nodes until we actually use them.

Swift SVN r5780
2013-06-24 17:17:34 +00:00