Commit Graph

489 Commits

Author SHA1 Message Date
Joe Groff
fd457fb343 Revert "IRGen/Runtime: Use relative addresses in nominal type descriptors."
This reverts commit fbb832665a. It causes LLVM to complain with
"Cannot represent a subtraction with a weak symbol" when targeting Linux.
2015-12-11 15:41:11 -08:00
Joe Groff
fbb832665a IRGen/Runtime: Use relative addresses in nominal type descriptors.
Decrease the size of nominal type descriptors and make them true-const by relative-addressing the other metadata they need to reference, which should all be included in the same image as the descriptor itself. Relative-referencing string constants exposes a bug in the Apple linker, which crashes when resolving relative relocations to coalesceable symbols (rdar://problem/22674524); work around this for now by revoking the `unnamed_addr`-ness of string constants that we take relative references to. (I haven't tested whether GNU ld or gold also have this problem on Linux; it may be possible to conditionalize the workaround to only apply to Darwin targets for now.)
2015-12-11 15:21:12 -08:00
Leo Shimonaka
70e66973ee Fix spelling error in documentation / comments / method name 2015-12-05 00:28:08 -05:00
Slava Pestov
c749046b57 IRGen: Remove ancient runes, NFC 2015-11-16 11:11:08 -08:00
Slava Pestov
a05f6c80f6 IRGen: Use metadata accessors for types with resilient layout
If a struct has fixed layout but contains fields which are opaque,
or if the struct itself is opaque, use a metadata accessor function
instead of loading the metadata directly.

Let's say that A and B are two structs defined in the same module,
and B has a fixed size. This patch adds support for these two cases:

1) Fixed-layout struct A contains resilient struct B
2) Resilient struct A contains resilient struct B

In case 1),

a) Inside X: A is fixed-size and has constant metadata
 i) Direct metadata access can be performed on A and B
 ii) Direct field access can be performed on A and B
d) Outside X: B has an opaque layout
 i) Metadata accessor must be called for A and B
 ii) Fields of A do not have constant offsets, instead the offsets
     must be loaded from type metadata

Case 2) is the same as above except ii) does not apply, since fields
of resilient structs are manipulated via accessors.

Eventually, we will use metadata accessor functions for all public
struct and enum types.
2015-11-16 10:37:14 -08:00
Slava Pestov
1adf7534d7 IRGen: Collapse down ResilienceScope enum
John and I discussed this and agreed that we only need two cases here,
not four. In the future this may be merged with ResilienceExpansion,
and become a struct with additional availability information, but
we're definitely sure we don't need four levels here.
2015-11-13 17:56:17 -08:00
Slava Pestov
19458cef2c IRGen: Preliminary resilient struct support
Add a new ResilientStructTypeInfo. This is a singleton since
all resilient structs have opaque payloads and are accessed
through value witness tables.

With this in place, flesh out IRGenModule::isResilient() and
use the new singleton to convert resilient structs.

Note that the old isResilient() was hard-coded to report that
all Clang-imported classes are "resilient". Now that this has
been unified with NominalTypeDecl::hasFixedLayout(), we will
report Clang-imported classes are "resilient" at the SIL level.
This should not introduce any semantic differences at this
point.

Unlike SIL, where currently resilient types are always resilient
even when used from the same module, IRGen is able to perform
direct manipulation of resilient structs from the current
module, since IRGen's type lowering has a resilience scope
plumbed through.

Note that we do not yet support laying out structs and classes
containing resilient fields -- this will come in a future patch.
2015-11-13 13:20:50 -08:00
Michael Gottesman
9fb54bf4bf Fix for upstream ilist changes. 2015-11-11 16:07:41 -08:00
Slava Pestov
fe62d2b077 Nuke some duplication around SILModule::lookUpFunction() uses, NFC
Swift SVN r32939
2015-10-28 18:28:49 +00:00
Slava Pestov
afa41c056c IRGen: Fix OBJC_CLASS_$_ clash if Clang emits first
IRGen emits lazily-emitted definitions after emitting Clang declarations.
So an internal function that references an Objective-C class global and
is itself referenced from after a public function can observe
a OBJC_CLASS_$_ global defined by Clang.

Use a similar strategy as the Clang patch, just bitcast the global if it
exists already.

Fixes <rdar://problem/23200656>.

Swift SVN r32845
2015-10-23 06:33:36 +00:00
Michael Gottesman
113fac2871 Update use of GlobalAlias::create API for upstream changes.
Swift SVN r32798
2015-10-21 21:45:08 +00:00
Slava Pestov
54dd7892e8 SIL: Emit native ivar destroyer and store it in class metadata
Swift SVN r32644
2015-10-13 00:27:57 +00:00
Joe Groff
42c71b7972 Don't mangle directness into type metadata symbols.
Anywhere we can't directly address type metadata in Swift, we've found we need a function call. Directness isn't useful here.

Swift SVN r32626
2015-10-12 17:22:40 +00:00
John McCall
76e324a950 Refactors leading towards the use of protocol witness table access functions.
This re-applies r32541 with a few changes to the demangling logic and associated test fixes.

Swift SVN r32553
2015-10-09 05:49:18 +00:00
Erik Eckstein
19bb23a63f Revert r32541 "Refactors leading towards the use of protocol witness table access functions."
It broke the build: 2 demangle tests failed.




Swift SVN r32552
2015-10-09 04:42:19 +00:00
John McCall
9af9b9914d Refactors leading towards the use of protocol witness table
access functions.  NFC for now.

Swift SVN r32541
2015-10-09 01:06:06 +00:00
John McCall
a945bacc6b Split GenProto.cpp into three files; NFC.
- GenProto.cpp for protocols and protocol conformances
  - GenExistential.cpp for existential type layout and operations
  - GenArchetype.cpp for archetype type layout and operations

Swift SVN r32493
2015-10-07 18:41:12 +00:00
Nadav Rotem
7c1e5236a7 Refactor the code that checks for owned parameters. NFC.
Swift SVN r32478
2015-10-06 23:53:55 +00:00
Nadav Rotem
bb9aa3aedd Teach IRGen to emit the 'readonly' function attribute.
Teach IRGen to emit the llvm function attribute 'readonly' for functions that
are annotated with the @effects(readonly) attribute.

Swift SVN r32477
2015-10-06 23:53:53 +00:00
Joe Groff
dd9f28e1df IRGen: Emit protocol conformances on the parallel IRGen path too.
The new implementation needs to happen after all source files have been built and before lazy definitions are emitted, but I neglected to insert it in the parallel IRGen path. Fixes rdar://problem/22825770.

Swift SVN r32189
2015-09-23 22:37:37 +00:00
Chris Lattner
5c5ed635a4 add a use of an unused variable, it seems that an unused 'foreignCandidate'
might be a bug?


Swift SVN r31937
2015-09-14 21:49:29 +00:00
Joe Groff
f78fc20271 IRGen: Remove workarounds for rdar://problem/22467267.
Lang fixed MCJIT to support subtractor relocations in LLVM, so we can use direct relative references in JITed metadata now.

Swift SVN r31904
2015-09-11 19:30:57 +00:00
Joe Groff
9eea4d3838 IRGen: Rename TypeMetadataAccessStrategy -> MetadataAccessStrategy.
NFC, but this set of access modes applies more generally to other kinds of metadata that may need to be guarded by accessors, such as witness tables.

Swift SVN r31838
2015-09-10 00:51:05 +00:00
Joe Groff
e4ae6a4e16 IRGen: Avoid using the GOT for public symbols in the same TU.
This time, with yet another workaround for rdar://problem/22450593 to avoid an MC bug for 32-bit Mach-O.

Swift SVN r31559
2015-08-28 19:44:42 +00:00
Joe Groff
79364849ac Revert "IRGen: Avoid using the GOT for public symbols in the same TU."
This reverts commit r31557. It breaks on i386.

Swift SVN r31558
2015-08-28 19:16:51 +00:00
Joe Groff
a8fb6aebb5 IRGen: Avoid using the GOT for public symbols in the same TU.
Swift SVN r31557
2015-08-28 19:07:47 +00:00
Joe Groff
7e15a0dde7 Add rdar references to FIXMEs for rdar://problem/22467267 workarounds.
Swift SVN r31556
2015-08-28 18:13:50 +00:00
Joe Groff
773eadb9f2 IRGen/Runtime: Populate the runtime protocol conformance table with relative references.
By using relative references, either directly to symbols internal to the current TU, or to the GOT entry for external symbols, we avoid unnecessary runtime relocations, and we save space on 64-bit platforms, since a single image is still <2GB in size. For the 64-bit standard library, this trades 26KB of fake-const data in __DATA,__swift1_proto for 13KB of true-const data in __TEXT,__swift2_proto. Implements rdar://problem/22334380.

Swift SVN r31555
2015-08-28 18:07:22 +00:00
Joe Groff
43d620c7e0 IRGen: Export direct metadata symbols at the address point of the metadata object.
This is more resilient, since we want to be able to add more information behind the address point of type objects. The start of the metadata object is now an internal "full metadata" symbol.

Note that we can't do this for known opaque metadata from the C++ runtime, since clang doesn't have a good way to emit offset symbol aliases, so for non-nominal metadata objects we still emit an adjustment inline. We also aren't able to generate references to aliases within the same module due to an MC bug with alias refs on i386 and armv7 (rdar://problem/22450593).

Swift SVN r31523
2015-08-27 05:18:38 +00:00
Joe Groff
f705c561e3 Revert "IRGen: Export direct metadata symbols at the address point of the metadata object."
This reverts commit r31515. It causes an LLVM error on the release bots.

Swift SVN r31516
2015-08-27 01:44:56 +00:00
Joe Groff
8e2ce60f5b IRGen: Export direct metadata symbols at the address point of the metadata object.
This is more resilient, since we want to be able to add more information behind the address point of type objects, and also makes IR a lot less cluttered. The start of the metadata object is now an internal "full metadata" symbol.

Note that we can't do this for known opaque metadata from the C++ runtime, since clang doesn't have a good way to emit offset symbol aliases, so for non-nominal metadata objects we still emit an adjustment inline.

Swift SVN r31515
2015-08-27 01:34:22 +00:00
Jordan Rose
0733ba42c9 Allow @NSManaged to be applied to methods.
Core Data synthesizes Key-Value-Coding-compliant accessors for @NSManaged
properties, but Swift won't allow them to be called without predeclaring
them.

In practice, '@NSManaged' on a method is the same as 'dynamic', except
you /can't/ provide a body and overriding it won't work. This is not the
long-term model we want (see rdar://problem/20829214), but it fixes a
short-term issue with an unfortunate workaround (go through
mutableOrderedSetValueForKey(_:) and similar methods).

rdar://problem/17583057

Swift SVN r30523
2015-07-23 02:08:55 +00:00
Slava Pestov
871d71a555 Sema: Differentiate between 'class is @objc' and 'class has implicitly @objc members'
Generic subclasses of @objc classes are thus no longer @objc, but still
have implicitly @objc members.

Explicit @objc on generic classes or classes that inherit from @objc
classes is now forbidden with a diagnostic. Users need to know that
while they can override Objective-C methods and properties in such
a class, they cannot refer to the class by name from Objective-C code,
since it will not appear in the bridging header.

Fixes <rdar://problem/21342574>.

Swift SVN r30494
2015-07-22 06:34:20 +00:00
Joe Groff
9c5cdaaceb IRGen: Register class property accessors with the metaclass, not the class object, in JIT mode.
Fixes rdar://problem/19069918.

Swift SVN r30453
2015-07-21 18:03:15 +00:00
Slava Pestov
dd2b4a9299 IRGen: Fix emission of categories with @NSManaged properties
The FIXME comment no longer applied and the if statement didn't make
sense. Perhaps the 'break' was at one point meant to be a 'continue',
however now we seem to correctly handle emission of a property
descriptor for a property without accessors.

Fixes <rdar://problem/21474718>.

Swift SVN r30132
2015-07-13 00:20:38 +00:00
Doug Gregor
3023a710fc Split TypeBase::isDependentType() into isTypeParameter() and hasTypeParameter().
The isDependentType() query is woefully misunderstood. Some places
seem to want it to mean "a generic type parameter of dependent member
type", which corresponds to what is effectively a type parameter in
the language, while others want it to mean "contains a type parameter
anywhere in the type". Tease out these two meanings in
isTypeParameter() and hasTypeParameter(), respectively, and sort out
the callers.

Swift SVN r29945
2015-07-07 21:20:54 +00:00
Dmitri Hrybenko
2fc1cbe8c1 Adjust to the new IRBuilder APIs
Swift SVN r29692
2015-06-25 22:01:24 +00:00
Jordan Rose
49e1a746e0 [IRGen] Bitcast SIL globals that don't have the right LLVM type.
This comes up when the SIL global actually refers to a static global defined
in C. In these cases Clang may have already emitted the global with a
different type---one appropriate for Clang, but not for Swift. By the time
we get to this part of the code, we should have already rejected anything not
layout-compatible, so just do the bitcast and be done with it.

Reviewed by John.

rdar://problem/21361469

Swift SVN r29471
2015-06-17 23:26:13 +00:00
Jordan Rose
f335128e40 [IRGen] Don't wait until we find libswiftCore to autolink libobjc.
No intended functionality change.

Swift SVN r29443
2015-06-17 04:48:10 +00:00
Jordan Rose
c516ef9223 [IRGen] Remove unnecessary IRGenOptions flag HasUnderlyingModule.
The test that it's guarding is cheap enough to do all the time, and we
don't have any interesting configurations where it's not set any more.

Swift SVN r29442
2015-06-17 04:48:09 +00:00
Joe Groff
a321938d34 IRGen: Peephole (copy_addr to [initialization] (alloc_stack)) operations to use initializeBuffer value witnesses.
This saves a value witness call in the common case where a generic local variable or temporary is initialized from another value.

Swift SVN r29366
2015-06-12 16:59:14 +00:00
Arnold Schwaighofer
15ff698409 IRGen: Give ClangCodeGen a chance to emit its translation unit's global state
We need this because that global state includes tables like llvm[.compiler].used
which would otherwise be sorely missed.

This fixes an issue of the clang importer that would cause us to fail whenever
we imported a function (say it is marked as static inline) that performs an
objective-c method call and we optimize the code. The optimizer would not see
the objective-c selector global variable (which is marked private) as being
"used by unkown i.e the objc runtime" and would rightly assume it could
propagate the value of the global variable's initializer value as a constant to
loads of the global variable.

Now we call the ClangCodeGenerators translation unit finalization code which
will emit these tables and other module flags. We need to take care that we
merge those datastrutures with datastructures that we emit from swift's IRGen.

rdar://21115194

Swift SVN r29176
2015-05-31 00:01:29 +00:00
Doug Gregor
b8995b0aa3 Transform the Module class into ModuleDecl.
Modules occupy a weird space in the AST now: they can be treated like
types (Swift.Int), which is captured by ModuleType. They can be
treated like values for disambiguation (Swift.print), which is
captured by ModuleExpr. And we jump through hoops in various places to
store "either a module or a decl".

Start cleaning this up by transforming Module into ModuleDecl, a
TypeDecl that's implicitly created to describe a module. Subsequent
changes will start folding away the special cases (ModuleExpr ->
DeclRefExpr, name lookup results stop having a separate Module case,
etc.).

Note that the Module -> ModuleDecl typedef is there to limit the
changes needed. Much of this patch is actually dealing with the fact
that Module used to have Ctx and Name public members that now need to
be accessed via getASTContext() and getName(), respectively.

Swift SVN r28284
2015-05-07 21:10:50 +00:00
Adrian Prantl
de7de7db9c Debug info: Don't emit externally defined global variables.
rdar://problem/20507438

Swift SVN r28276
2015-05-07 18:14:55 +00:00
Manman Ren
e94aae06da [Function Attribute] add target-cpu and target-features sets if they're non-null.
All llvm::Functions created during IRGen will have target-cpu and target-features
attributes if they are non-null.

Update testing cases to expect the attribute in function definition.
Add testing case function-target-features.swift to verify target-cpu and
target-features.

rdar://20772331


Swift SVN r28186
2015-05-05 23:19:48 +00:00
Erik Eckstein
3940797583 IRGen: Do a better distribution of functions to multi-threaded compiled modules.
Instead of putting a function without an associated source-file into the primary module,
it is now put into the module which first references the function.



Swift SVN r28116
2015-05-04 15:30:41 +00:00
David Farler
91c64fdbb1 Stop re-exporting the Objective-C library
and link it properly. This is needed to embed LLVM bitcode sections
in the standard library and overlays. The linker doesn't support
embedded bitcode and reexport flags (among others).

rdar://problem/20750099

Swift SVN r28052
2015-05-01 22:24:14 +00:00
Doug Gregor
009b38d4a0 Stop using getProtocols() in IRGen. NFC
Swift SVN r27973
2015-04-30 16:13:41 +00:00
Slava Pestov
fafd0b83ee Attempt to properly handle static global variables
This is based on Jordan Rose's patch from rdar://problem/17597453.

Swift SVN r27821
2015-04-27 22:16:37 +00:00
Slava Pestov
892b5af3f7 IRGen: Simplify LinkInfo::createVariable()
llvm::Module::getNamedGlobal() already returns an llvm::GlobalVariable;
no need to cast. NFC

Swift SVN r27808
2015-04-27 18:55:47 +00:00