Commit Graph

5925 Commits

Author SHA1 Message Date
Jordan Rose
5ad871ecd6 Adopt llvm::function_ref for callbacks that aren't persisted.
...removing a few other constructs that were doing the same thing
(mostly from me).

No functionality change.

Swift SVN r23294
2014-11-13 00:19:03 +00:00
Doug Gregor
f204351e7e Implement Clang importer support for finding Objective-C methods by selector.
This functionality doesn’t really change what we accept right now, because we eagerly import all of the methods of a class when we do *any* kind of lookup into the class. However, when we manage to stop doing that, this operation will become more important.

Swift SVN r23289
2014-11-12 23:18:42 +00:00
Jordan Rose
a4a6b42604 [Driver] Only run compile jobs if needed.
This teaches the driver's Compilation to not run jobs where the base input
is older than the main output (r23221) when we're tracking dependencies.
After a compile command finishes, anything that depended on the file that
just got compiled will get scheduled.

This has the nice side effect of trying to rebuild changed files first.

The tests here aren't really testing the dependency graph yet, because the
files don't include any dependencies. I'll be adding several more test
scenarios in the next few commits.

Part of rdar://problem/15353101

Swift SVN r23273
2014-11-12 18:06:10 +00:00
Jordan Rose
6ca70b3c49 [Driver] Add debug option -driver-use-frontend-path.
This will be used to test dependency analysis by substituting a different
executable to use as the frontend.

For debugging purposes only.

Swift SVN r23272
2014-11-12 18:06:08 +00:00
David Farler
c453eb4c48 Add Set type.
<rdar://problem/14661754> TLF: [data-structure] Set<T> data type + Bridging from NSSet

Swift SVN r23262
2014-11-12 07:07:00 +00:00
Joe Groff
08fe138808 Runtime: Generate a human-understandable name for Any.Type.
Expose this in the stdlib as _typeName(Any.Type) -> String, pending API review.

Swift SVN r23254
2014-11-11 23:38:24 +00:00
Michael Gottesman
7a2e1fb4d3 [arc-opts] After the arc optimizer converges, run another round of the ARC
optimizer freezing releases in the epilogue of functions that match to
SILArguments. This allows us to treat all such SILArguments throughout the
entire function as having a post dominating release.

<rdar://problem/18923030>

Swift SVN r23253
2014-11-11 23:37:09 +00:00
Chris Willmore
f723b05672 Don't remove 'with' from ObjC method arg name if resulting name is keyword.
Also, remove calls to isSwiftReservedName in
ClangImporter::Implementation::importName(), since 'true' and 'false'
are now keywords and rdar://problem/13187570 is no longer a problem.

rdar://problem/18797808

Swift SVN r23244
2014-11-11 19:34:53 +00:00
Arnold Schwaighofer
06a0a23562 Add a destructor memory effect analysis
This adds an analysis to the compiler that identifies types that are may store
to memory on destruction.

It adds a compiler known protocol _DestructorSafeContainer that allows the
standard library to identify containers whose destructor's memory effects
depends strictly on the type parameters of the container.

Array<T> : _DestructorSafeContainer {} may not store to memory during
destruction if the bound T is a type that does not store to memory on
destruction.

This is needed to deduce that for example Array<Array<Int>> is does not store to
memory on destruction (e.g during a call to release).

rdar://18940376

Swift SVN r23242
2014-11-11 19:27:41 +00:00
Joe Groff
7ce4ea860c IRGen/Runtime: Handle non-class-metatype to ObjC existential casts.
These always fail, and it doesn't make sense to inline this check into the cast site, so provide additional runtime functions for metatype-to-objc-existential casts.

Swift SVN r23237
2014-11-11 18:51:09 +00:00
Joe Groff
2475bd1e4f Clean up platform conditionals.
Thanks Jordan!

Swift SVN r23235
2014-11-11 17:05:56 +00:00
Adrian Prantl
dd4032ee41 Modify the Mangler to recursively deal with sugared types.
Unless DWARFmangling is set all methods still expect a CanonicalType.

Fixes <rdar://problem/17042576> [6A214t] Debug information has wrong type for dispatch queue

Swift SVN r23226
2014-11-11 01:32:12 +00:00
Jordan Rose
8b5d763e39 [Driver] Add a new DependencyGraph class.
...and some basic unit tests for it.

The purpose of this class is to track dependencies between opaque nodes.
The dependency edges are (kind, string) pairs, where the "kind"
distinguishes different kinds of dependencies (currently "top-level names"
and "types that we do lookup on"). The step is to make use of it in
running compile commands.

The YAML-based file format is only for bring-up and testing purposes.
I intend to switch it to a bitcode-based format in the long run.

Part of rdar://problem/15353101

Swift SVN r23223
2014-11-11 00:43:29 +00:00
Jordan Rose
3a52f2ad5c [Driver] Provide a single API to iterate over all valid file types.
Previously we had three separate instances of iterating from TY_INVALID+1
to TY_LAST, completely breaking type safety. Now we have a nice little
wrapper that takes a closure, which should inline down to the same thing
anyway.

Also, eliminate TY_LAST and just use TY_INVALID as our sentinel.

Swift SVN r23222
2014-11-11 00:43:28 +00:00
Jordan Rose
0364724ec3 [Driver] Add an mtime test for single-file compilation jobs.
The Swift compiler is always fed the entire list of files in a module.
If it's told to track dependencies, though, it should look to see if it
actually needs to recompile all of its inputs. The first step in this is
to see which files are actually dirty, which it does by comparing the mtime
of each source file with the mtime of its output object file. If a source
file is not dirty, it only needs to be rebuilt if it depends on something
in a dirty file.

Nothing actually uses this information yet, but we can print it with
-driver-print-bindings!

Swift SVN r23221
2014-11-11 00:43:27 +00:00
Jordan Rose
1fdf0e48b4 [Driver] Add -emit-reference-dependencies to the driver.
This just adds another possible output kind and forwards it to the frontend.
Note that in builds without an output map, this will just dump the dependencies
next to the output file, which is a temp file whose name is chosen randomly.
That's not so useful, but we can fix it later.

Part of rdar://problem/15353101

Swift SVN r23220
2014-11-11 00:43:22 +00:00
Michael Gottesman
3d396f8b12 [arc-analysis] Refactor OwnedArgToEpilogueReleaseMatcher from FunctionSigOpts.
Given a function F, this utility class attempts to match up owned arguments with
releases in the epilogue of the function.

I am refactoring this from FunctionSigOpts so I can use it in the ARC optimizer.

<rdar://problem/18923030>

Swift SVN r23219
2014-11-11 00:42:30 +00:00
Doug Gregor
b27e88b70b Record Objective-C method lookup tables in Swift modules.
Include a mapping from Objective-C selectors to the @objc methods that
produce Objective-c methods with those selectors. Use this to lazily
populate the Objective-C method lookup tables in each class. This makes
@objc override checking work across Swift modules, which is part of
rdar://problem/18391046.

Note that we use a single, unified selector table, both because it is
simpler and because it makes global queries ("is there any method with
the given selector?") easier.

Swift SVN r23214
2014-11-11 00:19:03 +00:00
Roman Levenstein
3910c25da1 Minor re-factoring: Move the logic to decide if a given instruction can be (easily) duplicated into SILInstruction. So far it was mainly used by jump-threading related optimizations. But it could be generally useful, or at least generally important, to optimizations that want to duplicate code.
Swift SVN r23213
2014-11-10 23:15:07 +00:00
Joe Groff
7ee99eb9d3 Runtime: Workaround for rdar://problem/18889711.
LLVM treats 'consume' as 'acquire' on ARM64, emitting an unnecessary barrier.

Swift SVN r23180
2014-11-08 17:17:49 +00:00
Doug Gregor
b3badc601a Handle consistency checking that requires the entire module.
Objective-C method unintended override checking is one such case where
properly checking unintended overrides requires us to essentially look
at the whole module, because one translation unit may declare
something that produces an Objective-C method "setFoo:" in a
superclass while another translation unit declares something with a
distinct name that produces an Objective-C method "setFoo:". So, when
we don't have a primary file (e.g., when we're doing the merge-module
step), delay such checks until after all the source files for the
module have been type-checked. When there is a primary file, we
perform the checking that we can based on type checking that primary
file (and whatever got touched along the way), so we get a subset of
the proper diagnostics.

Swift SVN r23179
2014-11-08 06:20:57 +00:00
Doug Gregor
3df2c11c8a Diagnose Objective-C method overrides not reflected as Swift overrides.
Diagnose cases where the use of @objc will produce Objective-C methods
that end up overriding an Objective-C method in a superclass, when
that override is not properly represented as an override in the Swift
type system. This can happen when the Objective-C methods are produced
by different kinds of entities. For example:

  class Super {
    @objc var property: Int
  }

  class Sub : Super {
    @objc func setProperty(property: Int) { }
  }

In Swift, Sub.setProperty and Super.property are completely
unrelated. However, both produce an Objective-C instance method with
the selector "setProperty:", so we end up with unexpected overriding
behavior. Diagnose this whenever it occurs, regardless of the kind of
@objc entity that produced the Objective-C methods: initializers,
deinitializers, methods, properties, or subscripts.

Implements the rest of the intended functionality of
rdar://problem/18391046, with the caveat that there are two remaining
classes of bugs:
  1) Superclasses defined in a module (or imported from a Clang
  module) aren't handled properly yet; we might not see those methods.
  2) We won't properly detect all of these failures when the methods
  are scattered across different source files in the same module.

Swift SVN r23170
2014-11-08 00:55:45 +00:00
Connor Wakamo
23ea8e59c8 Made LazyLoaderArray's length type fit in a 32-bit pointer.
Per Jordan, it's OK to assume that nothing will have more than 2 billion members
or protocols, so make this an llvm::Fixnum<31> instead of an llvm::Fixnum<63>.

Swift SVN r23167
2014-11-07 23:53:38 +00:00
Graham Batty
c835beb0b8 Remove IRGenOptions objc-interop flag.
Swift SVN r23166
2014-11-07 22:39:13 +00:00
Joe Groff
cc6d8035d2 Sema: Allow casts to arbitrary existential types at the sema level.
Still work to do at the IRGen/runtime level before this will work in all cases.

Swift SVN r23151
2014-11-07 01:17:53 +00:00
Joe Groff
32d148c807 Runtime: Improve type safety when working with witness tables.
Declare an opaque WitnessTable type instead of throwing void* around everywhere.

Swift SVN r23149
2014-11-07 01:17:51 +00:00
Doug Gregor
89e5e5b6fa Diagnose redeclarations of Objective-C methods.
@objc methods, initializers, deinitializers, properties, and
subscripts all produce Objective-C methods. Diagnose cases where two
such entities (which may be of different kinds) produce the same
Objective-C method in the same class.

As a special exception, one can have an Objective-C method in an
extension that conflicts with an Objective-C method in the original
class definition, so long as the original class definition is from a
different model. This reflects the reality in Objective-C that the
category definition wins over the original definition, and is used in
at least one overlay (SpriteKit).

This is the first part of rdar://problem/18391046; the second part
involves checking that overrides are sane.

Swift SVN r23147
2014-11-07 01:15:14 +00:00
Jordan Rose
c4fd29eb0b [Driver] Eliminate the common base class of Command and JobList.
...and rename Command to Job (previously the name of the base class).

We never generated job lists directly contained in other job lists, so
let's not even worry about this case. We may some day need to break Job
out into separate subclasses (Clang has Command and FallbackCommand in
addition to JobList), but we should be able to keep the list separate.

No intended functionality change.

Swift SVN r23144
2014-11-07 00:10:18 +00:00
Jordan Rose
96b3edbfde [Driver] When a command finishes, don't try to reschedule ALL other commands.
Instead, if we can't schedule a command, record why it was blocked. When the
blocking command completes, we then try to reschedule everything that was
blocked on it.

This is also more robust for cross-job-list dependencies---things like the
link job depending on the merge-module job and both depending on compile jobs.

Swift SVN r23143
2014-11-07 00:10:13 +00:00
Joe Groff
e2cd398caf Runtime: Remove dead casting entry points.
Swift SVN r23138
2014-11-06 22:19:29 +00:00
Erik Eckstein
1f8a9eb5c3 Optimize the generated == function for enums.
Before it was done with a big switch statement, which remained a switch until the final code.
Now it's done by getting an integer index for both enums and just doing an integer compare.
This results in a simple compare in the final code.

Note that the == function is only generated for enums without payload. Getting the integer
index of such enums is a cheap operation.




Swift SVN r23129
2014-11-06 16:04:50 +00:00
Joe Groff
5e682924f6 AST: Drop insignificant CheckedCastKinds.
We'd like to kill this enum off eventually, since the runtime inevitably needs to be able to handle arbitrary checked casts in opaque contexts, and SILGen and IRGen can deal with picking more optimal runtime entry points for specific casts. Only the container bridging kinds are still depended on anymore, and even those ought to eventually be handlable by the runtime in 'x as T' situations. NFC yet.

Swift SVN r23127
2014-11-06 04:05:05 +00:00
Joe Groff
8ba1f42c63 Remove stray "#if 0 ||" and add missing else.
Swift SVN r23125
2014-11-06 01:32:11 +00:00
Graham Batty
d15c24e25b Changes to runtime library to support non-objc targets
Swift SVN r23122
2014-11-05 23:17:07 +00:00
Doug Gregor
8b1d818fb5 Move some archetype-only bits from SubstitutableType to ArchetypeType. NFC
Swift SVN r23120
2014-11-05 21:19:13 +00:00
Joe Groff
763ce97193 Runtime: Tighten up barriers in foreign type metadata.
When there's no init function, we can do relaxed loads and stores, because the metadata record will not change in the course of canonicalization. However, if there is initialization, we need to do a release-consume in order to ensure the initialization is visible to readers.

Swift SVN r23119
2014-11-05 19:16:10 +00:00
Graham Batty
63a429f16e Changes to code generation to support non-objc targets
Swift SVN r23118
2014-11-05 18:05:55 +00:00
Erik Eckstein
da9f08aec8 Replace the default-entry with a corresponding case-entry in select_enum[ _addr], if possible.
This is exactly the same thing as I did for switch_enum.



Swift SVN r23116
2014-11-05 12:48:11 +00:00
Manman Ren
276af26e12 [Global Opt] adds GlobalGetter as one kind of SILDeclRef.
Also handles mangling, demangling, printing and parsing.

This is the first patch to use global getter for "let" globals.

rdar://16614767


Swift SVN r23106
2014-11-05 00:40:32 +00:00
Joe Groff
af0121f8e6 IRGen: Don't nonlazily realize classes (unless they ask).
We lazily realize classes when we access their metadata now, so there's no need to force the ObjC runtime to do this greedily anymore, except for classes that the runtime statically references. For those cases, add an @objc_non_lazy_realization class attribute that will put that class reference in the nlclslist section.

Swift SVN r23105
2014-11-05 00:19:37 +00:00
David Farler
23a86eda49 CmpXChg Builtin: allow 'weak', return {iNN, i1}
CmpXChg builtins now return (T, Bool) to match the LLVM return value.
Turn the tests back on and check extractvalue / inttoptr instructions.

<rdar://problem/17309776> Update modeling of cmpxchg builtin to handle weak-ness and separate success bit

Swift SVN r23104
2014-11-04 21:49:55 +00:00
Michael Gottesman
3ae10834d6 [ls-opts] Teach LoadStoreOpts how to forward smaller previous loaded items to the uses of larger later loads that partially alias the load.
This will help the ARC optimizer given future function sig optimization work and
is in general good since this has been a hole in our load store forwarding for a
while.

rdar://18831605

Swift SVN r23102
2014-11-04 19:44:06 +00:00
Joe Groff
58273118e2 Runtime: Make the invasive cache pointer in ForeignTypeMetadata atomic.
Per review from Dmitri and Greg. We can do relaxed loads (if we miss the store, we'll lock the global hashtable and find the metadata that way), but we need a seq_cst barrier when we store.

Swift SVN r23101
2014-11-04 17:43:29 +00:00
Joe Groff
914f47ff47 Runtime: Take the lock off the hot path of getForeignTypeMetadata again.
The race here was benign--we just end up writing the same uniqued value twice to the invasive cache. Relax the assertion that this used to trip.

Swift SVN r23098
2014-11-04 06:16:00 +00:00
Adrian Prantl
801dc3d20e Debug info: Actually encode the Swift version number instead of constant 1.
<rdar://problem/18729762> CU's RuntimeVersion field should have the Swift runtime version number

Swift SVN r23087
2014-11-03 17:48:06 +00:00
Joe Groff
90cb504b75 Runtime: Switch swift_conformsToProtocol over to the new implementation.
Swift SVN r23083
2014-11-03 06:12:18 +00:00
Joe Groff
e773d9a1aa IRGen: Unique the metadata for imported structs and enums at runtime.
Move the uniquing information for ForeignTypeMetadata behind the address point so we can share the layout between foreign classes and the existing layout for struct and enum metadata. Emit metadata records for imported structs and enums as foreign metadata candidates, and dynamically unique references to the metadata by calling swift_getForeignTypeMetadata.

Swift SVN r23081
2014-11-03 06:12:13 +00:00
Michael Gottesman
01a00347ca [aa] Add ProjectionPath::computeSubSeqRelation() and use it to teach AA how to check for partial aliasing.
rdar://18831605

Swift SVN r23076
2014-11-03 03:38:01 +00:00
Joe Groff
ef82526795 Runtime: Hack up support for conformance lookup on ObjC classes.
As a stopgap till IRGen properly emits indirected class references, support direct class reference protocol conformance records. This should get us to the point we can replace the dlsym hack with the new implementation.

Swift SVN r23073
2014-11-03 00:17:55 +00:00
Joe Groff
dfac9181dd Runtime: Add ObjC weak referencing support to SwiftObject.
We were missing -_tryRetain, -_isDeallocating, -allowsWeakReference and -retainWeakReference implementations on SwiftObject, so forming an ObjC weak reference to a pure Swift object always failed and produced a nil reference. Fixes rdar://problem/18637774.

This can be reapplied now that we properly call objc_destructInstance on deallocation.

Swift SVN r23070
2014-11-02 21:03:21 +00:00