Commit Graph

189 Commits

Author SHA1 Message Date
Jordan Rose
f028cd2b6a Call +load on all classes to register them with the Objective-C runtime.
When an Objective-C class is first used, the runtime will "realize" it,
i.e. create the rw-data and set a couple flags. With pure Swift classes,
though, it's possible to create an instance and then send a message to it
without ever sending a message to the class, in which case the runtime will
try to realize the /instance/ and mess everything up.

This patch "fixes" that by sending the +load message to all Swift classes,
to make sure they get realized before being used. This is a very
unfortunate cost in startup time but will be necessary for id-compatibility.

I will admit that I'm not sure why this is necessary for compiled classes.
I would have expected the object file to contain the necessary information
for the runtime to realize the classes in it by default. But perhaps
classes aren't realized until their first class message even in statically-
compiled code.

<rdar://problem/13154445>

Swift SVN r3951
2013-02-05 19:53:01 +00:00
Joe Groff
9e3724b562 REPL: Factor out 'print-or-dump' logic.
It crossed the "1, 2, or N" threshold.

Swift SVN r3923
2013-02-01 17:25:01 +00:00
Joe Groff
7350051ce7 REPL: Print original decl along with a typealias.
This allows you to print imported structs that were defined as 'typedef struct foo {} foo;', for which the original decl is otherwise inaccessible:

swift> :print_decl NSFastEnumerationState
typealias NSFastEnumerationState = NSFastEnumerationState
struct NSFastEnumerationState {
  ...
}

Swift SVN r3922
2013-02-01 17:19:16 +00:00
Dave Zarzycki
b36678214a Rename l_(paren|square)_(call|subscript)
Thanks Chris and John for the feedback.

Swift SVN r3893
2013-01-29 21:13:39 +00:00
Dave Zarzycki
735294a5c9 Make the lexing of '(', '[', and '.' consistent
The lexer now models tuples, patterns, subscripting, function calls, and
field access robustly. The output tokens are now better named as well:
l_paren and l_paren_call, and l_square and l_square_subscript. It
should be much more clear now which one to use. Also, the use of
l_paren or l_square will not arbitrarily flip flop if the token before
it is a keyword or if the token before it was the trailing ']' of an
attribute list. Similarly, tuples will always cause the lexer to produce
l_paren, regardless if the user typed '((x,y))' or '( (x,y))'.

When we someday add array literals, the right token is now naturally
falling out of the lexer.

Swift SVN r3840
2013-01-23 03:23:17 +00:00
Jordan Rose
fa197bff3a The latest OSX 10.9 SDKs have changed name of the ObjC module to ObjectiveC.
Update everywhere in Swift that refers to this module accordingly.

This change is backwards-incompatible and will require rebuilding any
Objective-C-based object files. I recommend a clean of swiftFoundation
and NSStringDemo at the very least. The swiftObjC target is also being
renamed to swiftObjectiveC for consistency.

Swift SVN r3784
2013-01-17 19:46:39 +00:00
Joe Groff
662afeaeef Add '-sil-i' option to driver.
Will allow immediate execution through SIL-irgen when SIL-irgen actually exists. Also add NeedsOutput_{First,Last} symbols to the ActionType enum so that the insidious enum ordering significance there is more obvious.

Swift SVN r3757
2013-01-14 02:57:04 +00:00
Joe Groff
aba47a6b90 Add a '-sil-emit-llvm' option to the driver.
It doesn't do anything but crash yet. Also add an entry point fo SILGen to Subsystems so that it can be invoked without dependency on SIL or SILGen.

Swift SVN r3738
2013-01-11 01:51:54 +00:00
Doug Gregor
6de1444c8e Build/install the Swift ObjC module.
Swift SVN r3658
2013-01-03 18:55:58 +00:00
Chris Lattner
47dbc4051c update for mainline LLVM header file moves.
Swift SVN r3634
2013-01-02 14:38:42 +00:00
Chris Lattner
5c126a8443 fix some typos in the REPL :help command's output.
Swift SVN r3622
2012-12-30 10:34:21 +00:00
Doug Gregor
c9ff336043 Add :print_decl <name> option to the REPL.
This REPL option is great for taking a quick peek at APIs, especially
imported ones. For example, NSMutableArray:
swift> :print_decl NSMutableArray
class [objc] NSMutableArray {
  func [objc] addObject(anObject : id)
  func [objc] insertObject(anObject : id, atIndex : NSUInteger)
  func [objc] removeLastObject()
  func [objc] removeObjectAtIndex(index : NSUInteger)
  func [objc] replaceObjectAtIndex(index : NSUInteger, withObject :
  id)
}
extension NSMutableArray {
  func [objc] filterUsingPredicate(predicate : NSPredicate)
}
extension NSMutableArray {
  func [objc] sortUsingDescriptors(sortDescriptors : NSArray)
}
extension NSMutableArray {
  static func [objc] arrayWithCapacity(numItems : NSUInteger) -> id
  constructor (initWithCapacity : NSUInteger)
  func [objc] initWithCapacity(numItems : NSUInteger) -> id
}
extension NSMutableArray {
  func [objc] addObjectsFromArray(otherArray : NSArray)
  func [objc] exchangeObjectAtIndex(idx1 : NSUInteger,
  withObjectAtIndex : NSUInteger)
  func [objc] removeAllObjects()
  func [objc] removeObject(anObject : id, inRange : NSRange)
  func [objc] removeObject(anObject : id)
  func [objc] removeObjectIdenticalTo(anObject : id, inRange :
  NSRange)
  func [objc] removeObjectIdenticalTo(anObject : id)
  func [objc] removeObjectsFromIndices(indices : CPointer<NSUInteger>,
  numIndices : NSUInteger)
  func [objc] removeObjectsInArray(otherArray : NSArray)
  func [objc] removeObjectsInRange(range : NSRange)
  func [objc] replaceObjectsInRange(range : NSRange,
  withObjectsFromArray : NSArray, range : NSRange)
  func [objc] replaceObjectsInRange(range : NSRange,
  withObjectsFromArray : NSArray)
  func [objc] setArray(otherArray : NSArray)
  func [objc] insertObjects(objects : NSArray, atIndexes : NSIndexSet)
  func [objc] removeObjectsAtIndexes(indexes : NSIndexSet)
  func [objc] replaceObjectsAtIndexes(indexes : NSIndexSet,
  withObjects : NSArray)
  subscript (idx : NSUInteger) : id {
    get

    set
  }
  func [objc] setObject(obj : id, atIndexedSubscript : NSUInteger)
  func [objc] sortUsingComparator(cmptr : NSComparator)
  func [objc] sortWithOptions(opts : NSSortOptions, usingComparator :
  NSComparator)
}



Swift SVN r3581
2012-12-21 22:13:57 +00:00
Doug Gregor
608b2d8a5b Allow a Swift and a Clang module to have the same name, and load both.
This change allows client code to just use, e.g.,

  import Foundation

to get both the Clang Foundation module and the Swift Foundation
module that provides various adaptation (typically via
extensions). At some point later, we can consider whether the modules
will end up in different namespaces somehow, or whether this is best
tackled by some kind of module re-export directive, but for now it's
convenient while we await the design of a real module system for
Swift.



Swift SVN r3405
2012-12-07 18:23:35 +00:00
Doug Gregor
07be3f3e7f Use the Objective-C runtime to unique selectors in JIT'd code.
When generating IR for the JIT, use sel_registerName() to unique the
selector references we generate. Static code doesn't need this
pessimization. Fixes <rdar://problem/12764732>.


Swift SVN r3403
2012-12-07 17:13:27 +00:00
Doug Gregor
1e689a936d Load the SwiftFoundation dylib when the corresponding Swift module is used.
This is a horrible, hard-coded hack so that the REPL and interpreter
will get the ObjC bridging definitions from the SwiftFoundation dylib
when the SwiftFoundation module is imported.



Swift SVN r3402
2012-12-07 16:20:01 +00:00
Doug Gregor
9fd5749835 Add a ":dump_decl <name>" command to the REPL, for debugging purposes.
This particular command is useful for exploring the ASTs generated by
the Clang importer. For example

  import Cocoa
  :dump_decl NSArray

shows all of the imported methods in both NSArray (which only has two
methods) and its categories (which have many, many methods).


Swift SVN r3275
2012-11-28 00:37:50 +00:00
Doug Gregor
83f2874ba1 Implement support for calling imported C functions from Swift.
There is no protection whatsoever if the Clang-to-Swift type
conversion produces something that Swift doesn't lower in an
ABI-compatible way. That will be dealt with later.


Swift SVN r3249
2012-11-27 00:34:48 +00:00
Dave Zarzycki
4d8739f083 Accept limitations of LLVM build system
1) Move the low-level runtime code into swift/runtime
2) Move the high-level "standard library" code into swift/stdlib

The key difference is that the 'runtime' contains language support logic
(like retain/release logic) that the compiler assumes to always exist
and may assume intimate details about the implementation. This library
will have intimate knowledge of the swift ABI.

In contrast, the 'stdlib' can be completely rewritten and the
language/compiler make little if any assumptions about it. It is
expected to reexport fundamental types and operators, and implement
fundamental policies (precedence, implicit conversions, etc).

Swift SVN r3045
2012-10-23 21:33:52 +00:00
Eli Friedman
dd299a35af Fix for LLVM TargetData -> DataLayout rename.
Swift SVN r2959
2012-10-09 23:18:24 +00:00
Doug Gregor
0f27e2885e In the REPL, it's fine now to run when we're type-checking with the
constraint solver.


Swift SVN r2950
2012-10-08 20:37:58 +00:00
Eli Friedman
8a2ede5b82 Zap extra semicolon which clang warns about.
Swift SVN r2896
2012-09-22 01:53:41 +00:00
Doug Gregor
c13ef4777e Replace the REPL command :dump_constraints with a way to toggle the
LangOptions bits for using the constraint solver and emitting its
diagnostics.


Swift SVN r2839
2012-09-12 20:56:03 +00:00
Doug Gregor
f059cfd22d Add a few more hacks to layer the application of a solved constraint system to an expression tree on the existing type checker.
Swift SVN r2838
2012-09-12 20:43:05 +00:00
Doug Gregor
39b9f431ee Separate out the setting of the "debug constraints" from "use the constraint solver" option; we want these to be independent. No functionality change, yet.
Swift SVN r2837
2012-09-12 20:22:48 +00:00
Doug Gregor
42b1ab6fbd Introduce a LangOptions class to capture various type-checker-tweaking flags. For now, introduce bits to enable the constraint solver and to enable debugging of the constraint solver, and use those to eliminate the "useConstraintSolver" bit that was threaded through too much of the type checker.
Swift SVN r2836
2012-09-12 20:19:33 +00:00
Doug Gregor
81d8f27bde When dumping constraints via TypeChecker::typeCheckExpression(), don't
rely at all on the existing type checker. Instead, just fold sequence
expressions (which are effectively a delayed parsing phase) and then
hand off the expression to the constraint solver.

Allows us to type-check expressions with operators, e.g., f + 1.


Swift SVN r2793
2012-08-27 18:33:20 +00:00
Doug Gregor
5999348a5a When we're dumping constraints for an expression in the REPL, don't
execute that expression.


Swift SVN r2717
2012-08-23 00:27:42 +00:00
Doug Gregor
0d7afbe5e0 Introduce an almost completely untested implementation of constraint
generation from an expression that has not been type-checked. One can
see the constraints introduced by an expression by using

  :dump_constraints <expression>

within the REPL. We're still missing several major pieces of
constraint generation:
  - We don't yet "open up" references to polymorphic types
  - We don't print out the child constraint systems in the dump, so
  it's not at all obvious what happens within overloading (and I'm not
  convinced I like my representation anyway)
  - There are no tests whatsoever
  - Member constraints are still very, very weird



Swift SVN r2624
2012-08-13 22:59:41 +00:00
Ted Kremenek
928924728a Delay initialization of 'LastValidLineEnd', as it was unconditionally
overwritten later.

Swift SVN r2493
2012-07-30 18:30:27 +00:00
Eli Friedman
b3a9da6fef MCJIT broke again... just turn it off until we can actually take it seriously.
Swift SVN r1879
2012-05-17 01:22:15 +00:00
Eli Friedman
8f290b63a8 Extend the ugly standard library hack so it works for static compilation. We should be inlining from the standard library now everywhere except the REPL.
Swift SVN r1792
2012-05-10 01:14:56 +00:00
Eli Friedman
760b49f4c6 Remove unused bit from IRGen options.
Swift SVN r1750
2012-05-05 03:19:11 +00:00
Eli Friedman
bf281fd1e1 Exclude REPL escapes from the output of :dump_source. <rdar://problem/11387569>.
Swift SVN r1744
2012-05-04 20:55:53 +00:00
Eli Friedman
ee254c5f58 Get rid of a bit of dead code from the REPL.
Swift SVN r1732
2012-05-03 23:51:31 +00:00
Eli Friedman
01385963ee Avoid JIT'ing swift.swift in both script mode and the REPL.
Swift SVN r1731
2012-05-03 23:48:00 +00:00
Eli Friedman
283ef8e455 Build swift.swift as part of the swift runtime. The CMake changes here aren't complete, but Doug said he would fix that.
This should be enough to allow statically compiling swift applications.  As followups, I'm going to additionally start installing swift.swift to a common location, and start  making REPL/script mode aware that these functions are available, so they don't bother to IRGen them.

I'm leaving around some files in runtime/ which aren't necessary with this commit; I'll delete them in a separate commit.



Swift SVN r1725
2012-05-03 22:31:23 +00:00
Eli Friedman
0b1405390d Add :dump_source to the REPL. <rdar://problem/11326637>.
Swift SVN r1724
2012-05-03 20:50:34 +00:00
Eli Friedman
49bf057b20 Disable non-leaf frame pointer elimination for both REPL and script modes.
Swift SVN r1720
2012-05-02 21:48:57 +00:00
Eli Friedman
2aee4db46f A couple tweaks for REPL editline usage; install default signal handlers so we get better handling for Ctrl+Z etc., and print a newline after the end of input if we showed a prompt. Fixes <rdar://problem/11364065>.
Swift SVN r1717
2012-05-02 20:38:27 +00:00
Eli Friedman
e31cc600d3 Make immediate/script mode use the LLVM optimizers and MCJIT, as part of my experiments with optimizations. No functional change for the REPL; I still need to work out how to call the optimizer there without either breaking the underlying assumptions of the JIT or re-JITing everything for every line. (Multi-module support in the JIT would be nice...)
Swift SVN r1711
2012-05-02 03:00:31 +00:00
Eli Friedman
dcebd1d95e Fix uninitialized member.
Swift SVN r1705
2012-05-01 23:00:43 +00:00
Eli Friedman
ba1caeb57a Fix a stupid mistake in the precompilation code for the REPL.
Swift SVN r1662
2012-04-26 21:32:59 +00:00
Howard Hinnant
88e1ec0c16 Use Eli's swift new c_putchar to move print(String) back into swift.swift :-)
Swift SVN r1632
2012-04-25 15:39:16 +00:00
Eli Friedman
2f3ff69d41 Some tweaks to module import to get the demo flow working.
Swift SVN r1625
2012-04-25 07:29:31 +00:00
Eli Friedman
d228618b8d Slightly expand the :help text.
Swift SVN r1624
2012-04-25 07:11:42 +00:00
Eli Friedman
b4ec884307 Add missing square bracket token to REPL brace matching.
Swift SVN r1623
2012-04-25 06:53:24 +00:00
Eli Friedman
e6865b3b23 Move the implementation of Char printing into swift.swift, and get rid of the old printChar. Fix a bug in IRGen I ran into while working on that.
Swift SVN r1620
2012-04-25 03:39:48 +00:00
Howard Hinnant
8856293d94 Two major changes here: Char has been renamed to Char8. This is a temporary hack with the intent that Char8 will soon dissappear. But I'm refactoring and didn't want to break things. A new type Char has been introduced. It behaves somewhat like a cross between a UInt32 and a pointer type. It compares like a UInt32. It has arithmetic like a pointer, with the difference_type being Int. The second major change is the introduction of StringCharRange (name donated by Doug). It is attempting to be a range over String respecting that String is stored as UTF-8. It is intended that an invariant of String is that it can only hold valid null-terminated UTF-8 (to reduce validation costs). I also modified the cpp implementation of printChar to accept UTF-32 and print it out via printf using UTF-8. Still to be done is address the FIXME's in String to transition to UTF-8. I'm hoping this can be done with the new StringCharRange and foreach. But I do not know for sure. I've run out of steam for the night (still on EDT). For those of you who have more steam for the night and are working hard towards our demo, please feel free to pick any of this up and modify it in whatever way helps the demo best, even if that means reverting it.
Swift SVN r1619
2012-04-25 02:36:27 +00:00
Eli Friedman
ee4d656007 Switch misc functions in swift.swift to use the new asmname attribute.
Swift SVN r1618
2012-04-25 02:13:09 +00:00
Doug Gregor
c70aa1ba27 Make String(0) actually print '0' rather than nothing ;)
Swift SVN r1612
2012-04-24 22:48:36 +00:00