Commit Graph

221 Commits

Author SHA1 Message Date
Doug Gregor
9400e890d3 Emit @objc classes using namespaced names under a new flag -enable-objc-mangling.
Centralize the logic for figuring out what name to use for a class or
protocol in the Objective-C runtime. When the flag is enabled (it's
still disabled by default), use mangled names for all Swift-defined
classes, including those that are @objc. Note that the naming is
determined in the AST, because we're also going to use this logic when
printing an Objective-C header for Clang's consumption. The mangled
names will always start with _Tt, so they're easy to recognize and
demangle in various tools or, eventually, in the Objective-C runtime.

The new test (test/IRGen/objc_mangling.sil) is the only test of this
behavior at the moment. The other test changes are due to the
centralized logic tweaking the names of internal constants (_DATA_*,
_CATEGORY_*, etc.).

This is the majority of <rdar://problem/15506580>.



Swift SVN r15588
2014-03-28 23:00:08 +00:00
Dmitri Hrybenko
866511e27d Add mangling for SubscriptDecls to allow us to produce USRs for them
<rdar://problem/16237251> USR generator skips SubscriptDecls


Swift SVN r14923
2014-03-11 18:03:04 +00:00
Doug Gregor
0bde325327 Collapse 'DynamicSelf' into 'Self'.
Swift SVN r14377
2014-02-26 05:04:05 +00:00
Joe Groff
89807a939e Mangle the protocol constraints on associated types in GenericParamLists.
A short-term fix to <rdar://problem/16079822> that keeps generic overloads from creating symbol collisions without requiring a larger migration of the debugger or other tools.

Swift SVN r14353
2014-02-25 21:56:04 +00:00
Argyrios Kyrtzidis
bb4b57c053 [IDE] Introduce ide::printDeclUSR() which uses the mangler to provide a USR for a swift symbol.
Swift SVN r14279
2014-02-23 06:54:48 +00:00
Chris Lattner
a5465680ff remove a bogus assert, allowing removal of some duplicated code.
Swift SVN r14086
2014-02-19 16:47:26 +00:00
John McCall
c7da19725a Allow the mangler to mangle accessor kinds and make
protocol conformance thunk generation handle accessors
correctly.

Swift SVN r14050
2014-02-18 21:53:10 +00:00
Chris Lattner
4a86056dff Progress towards putting subscript accessors into protocol witness tables.
This isn't testable yet, as it is blocked by at least two things:
 1. we can't put curried functions into witness tables (rdar://16079147),
    which is a problem given that subscript accessors are curried on their 
    index argument.
 2. accessors cannot silgen is curried form, we currently die in mangling.




Swift SVN r13947
2014-02-16 07:04:33 +00:00
Chris Lattner
153cfb1e1c move accessor mangling into Mangler::mangleEntity, where it can eventually be
used by witness thunk generation.


Swift SVN r13946
2014-02-16 06:38:56 +00:00
Joe Groff
802df0bdf3 Runtime: Do awful things to implement "swift_conformsToProtocol" for Swift protocols.
Given our constraints for 1.0, we can actually sort-of look up protocol conformances just by dlsym'ing the symbol for their protocol witness table, since we won't be implementing runtime witness table instantiation or private conformances anytime soon. To make this work for generic types, distastefully regress our mangling for protocol conformances by assuming all generic conformances are completely general to the unbound generic type and leave the generic parameters out of the mangling.

Swift SVN r13901
2014-02-14 05:15:32 +00:00
Joe Groff
1bbbcaaf98 Consider @auto_closure when mangling types.
We allow overloads on foo(() -> T) and foo(@auto_closure () -> T) in Sema, so they need distinct manglings. Fixes <rdar://problem/16045566>.

Swift SVN r13856
2014-02-13 03:02:22 +00:00
Joe Groff
30a3a9a0a0 SILGen: Hand down context generic params for reabstraction thunks independent from their type.
Pass the context generic params for a reabstraction thunk down to getOrCreateReabstractionThunk from the enclosing function, where it can either use them to define a new thunk or ignore them if it has an equivalent thunk already. Tweak the mangling of reabstraction thunks to use the generic signature with decontextualized "from" and "to" types instead of the generic param list.

Swift SVN r13763
2014-02-10 23:37:11 +00:00
Joe Groff
188b53c4ab AST: Fix up mangling of dependent types.
Don't fall through from GenericTypeParamType into DependentMemberType, and don't infinite loop on DependentMemberTypes. Oops.

Swift SVN r13720
2014-02-09 22:25:55 +00:00
Joe Groff
ab82fa1207 Mangle SILFunctionTypes from their interface types.
Make up manglings for generic signatures and their dependent GenericTypeParamTypes and DependentMemberTypes, as well as the generic signature of a GenericFunctionType or SILFunctionType. Use these to build the mangling for a SILFunctionType from its interface types.

Swift SVN r13537
2014-02-06 01:36:49 +00:00
Argyrios Kyrtzidis
48023490de [AST] Move AccessorKind enum to top-level so it can be forward declared.
No functionality change.

Swift SVN r13299
2014-02-01 08:50:15 +00:00
Doug Gregor
030770a8c2 Make DynamicSelf into its own special type node.
Making DynamicSelf its own special type node makes it easier to opt-in
to the behavior we want rather than opting out of the behavior we
don't want. Some things already work better with this representation,
such as mangling and overriding; others are more broken, such as the
handling of DynamicSelf within generic classes and the lookup of the
DynamicSelf type.


Swift SVN r13141
2014-01-30 05:36:20 +00:00
Greg Parker
b2846b546b Make Int a word-size type.
- Int and UInt are now struct types backed by Builtin.Word. Previously they
were typealiases for Int64; Int and Int64 are now distinct types.
- Mangled names 'i' and 'u' are now Int and UInt. Int64 is mangled longhand.
- Word is a typealias for Int. It is expected to go away in the future.
- Builtin.Word is unchanged.
- CLong and CUnsignedLong are typealiases for Int and UInt.
- FixedPoint.swift is now FixedPoint32.swift and FixedPoint64.swift. 
Reunifying these requires better builtins, especially for checked 
conversions (rdar://15472770).
- Updated many tests, mostly because Int is no longer spelled Int64 in sil.
- One check was removed from test decl/operator/operators.swift 
because it changed behavior when Int became a non-typealias 
type (rdar://15934688).



Swift SVN r13109
2014-01-29 12:21:19 +00:00
Chris Lattner
d407bc8fc4 Teach the parser to add the didSet/willSet functions to the enclosing
type, so we emit them.  Add mangler (and demangler) support for these.
Enhance our testcase to check to make sure that stores within these
specifiers are direct, they don't cause recursive infinite loops.

John, I picked w/W for the mangling letters, let me know if this is ok.


Swift SVN r13050
2014-01-28 05:15:56 +00:00
Chris Lattner
929ad99f08 Clean up and generalize the code pertaining to how a FuncDecl accessor
knows about the AbstractStorageDecl it works on.  NFC.



Swift SVN r12994
2014-01-27 17:57:38 +00:00
John McCall
a1b469ed2f ExplosionKind -> ResilienceExpansion. NFC.
Swift SVN r12364
2014-01-16 00:25:29 +00:00
John McCall
817e80bde5 Implicit conversions for UncheckedOptional.
rdar://15189000
rdar://15189009

Swift SVN r12260
2014-01-13 23:15:03 +00:00
Doug Gregor
fc7dfb2fae Start emitting .cxx_construct methods for Objective-C-derived classes.
When we're using Objective-C's memory allocation, emit .cxx_construct
methods whenever we have instance variables with in-class
initializers. Presently, these methods are just empty stubs.

Swift SVN r12211
2014-01-12 04:31:52 +00:00
Doug Gregor
3524a79fa0 Emit .cxx_destruct for destruction of ivars in Objective-C-derived classes.
The Objective-C runtime executes the .cxx_destruct method after the
last -dealloc has executed when destroying an object, allowing the
instance variables to remain live even after the subclass's
destructor/-dealloc has executed, which is important for memory
safety. This fixes the majority of <rdar://problem/15136592>.

Note that IRGenModule::getAddrOfIVarDestroyer() contains  an egregious
hack to find the ivar destructor SIL function via a linear
search. We need a better way to find SIL functions that we know exist,
because LinkEntity does not suffice.

Swift SVN r12206
2014-01-12 00:17:42 +00:00
Doug Gregor
99f31a9aa9 Mangle destructor context more directly.
Swift SVN r12198
2014-01-11 04:37:37 +00:00
Doug Gregor
0ed1e6d7f5 Switch mangleDestructorEntity() tover to accepting a DestructorDecl. NFC
Swift SVN r12161
2014-01-10 23:11:06 +00:00
Adrian Prantl
946dc5678b Debug info: Provide an in interface for LLDB to mangle types and refactor
some code in IRGenDebugInfo along the way.
This is WIP for rdar://problem/15498877.

Swift SVN r12146
2014-01-10 22:35:53 +00:00
Adrian Prantl
72c037acb1 Debug info: Emit the correct context for archetypes with a depth > 0 in
the Qq mangling.

<rdar://problem/15767642> Mangling for qualified archetypes of member functions has wrong index

Swift SVN r12075
2014-01-08 23:57:39 +00:00
John McCall
942d3b0e6c Fix the mangling of initializer contexts.
Swift SVN r11956
2014-01-06 22:18:05 +00:00
John McCall
4355a21a62 Mangle closures using their context and discriminator.
Swift SVN r11885
2014-01-04 04:37:57 +00:00
Chris Lattner
468ead25a6 allow 'var' and 'let' to appear in patterns (not just matching patterns).
This allows them to appear in argument lists of functions, enabling behavior
like this:

func test_arguments(a : Int, var b : Int, let c : Int) {
  a = 1  // ok (for now).
  b = 2  // ok.
  c = 3  // expected-error {{cannot assign to the result of this expression}}
}



Swift SVN r11746
2013-12-30 21:48:06 +00:00
Chris Lattner
9ae289de46 Drive the semantic wedge harder into lvalues. Now, instead of having one LValueType
with qualifiers on it, we have two distinct types:
 - LValueType(T) aka @lvalue T, which is used for mutable values on the LHS of an
   assignment in the typechecker.
 - InOutType(T) aka @inout T, which is used for @inout arguments, and the implicit
   @inout self argument of mutable methods on value types.  This type is also used
   at the SIL level for address types.

While I detangled a number of cases that were checking for LValueType (without checking
qualifiers) and only meant @inout or @lvalue, there is more to be done here.  Notably,
getRValueType() still strips @inout, which is totally and unbearably wrong.



Swift SVN r11727
2013-12-29 22:23:11 +00:00
Doug Gregor
be3463f32d Store a file-level DeclContext* in protocol conformances rather than a module.
We'll need to perform name lookup based on the file-level
DeclContext*, so the module no longer suffices. No functionality
change here yet.


Swift SVN r11523
2013-12-20 22:53:21 +00:00
John McCall
186c0243f1 Mangle the discriminator into local declaration names.
Swift SVN r11522
2013-12-20 22:50:51 +00:00
Joe Groff
017440165e Fix the weird capitalization of MetaTypeType.
Swift SVN r11475
2013-12-19 18:43:08 +00:00
John McCall
c5aa41ffd1 Change around some manglings to make them carry more
information and be easier to demangle.

Swift SVN r11423
2013-12-18 08:33:52 +00:00
Joe Groff
1f3c29b86c Give ProtocolConformance a getGenericParams() method.
It's useful to know what the open type variables in a generic protocol conformance are. For now, make the somewhat shaky assumptions that a NormalProtocolConformance for a bound generic type is for the DeclaredTypeInContext of its originating nominal type, that all type variables of the nominal type are open, and that specialized and inherited conformances bind all of the generic parameters.

Swift SVN r11274
2013-12-13 22:59:34 +00:00
John McCall
0bfa86673f Introduce (but don't yet create) a new kind of DeclContext for
various kinds of expressions that appear outside of local
evaluation contexts.

Swift SVN r11176
2013-12-12 03:36:17 +00:00
Joe Groff
88e5dece28 SILGen: Implement a visitor to produce witness tables.
Walk the ProtocolConformances of type and extension decls to produce SILWitnessTables for them. Work out the type of the witness function by applying substitutions from the witness map and lowering it at the abstraction level of the requirement, then emit a symbol for the witness function (but don't emit the body of the witness function just yet).

Swift SVN r11143
2013-12-11 21:40:44 +00:00
Adrian Prantl
22f1d8c7a6 Debug info: Repair emission of the swift.type type after introducing the
_Tta mangling.
Fixes <rdar://problem/15599592> Type for $swift.type arguments is now Builtin.RawPointer.metatype

Swift SVN r11046
2013-12-09 23:09:43 +00:00
Adrian Prantl
f8e227344c Mangler: Make sure to restore the state of the mangler after binding
generic parameters from parent decl contexts.
Fixes <rdar://problem/15599314> Crash in the Mangler.

Swift SVN r10929
2013-12-06 19:29:24 +00:00
Joe Groff
0ff977d407 Add a 'WitnessMethod' enumerator to AbstractCC.
We'll use this to represent the slightly-different polymorphic calling convention used for passing Self into protocol witnesses.

Swift SVN r10898
2013-12-06 01:32:35 +00:00
Adrian Prantl
66818859d2 Mangler: Clean up the Qq DeclContext mangling by cloning a fresh mangler.
Fixes <rdar://problem/15476638> Qq mangling points to wrong DeclCtx.

Swift SVN r10893
2013-12-06 00:39:49 +00:00
Dave Abrahams
7ab9d369aa [stdlib] Rename Char => UnicodeScalar
Swift SVN r10864
2013-12-05 17:30:37 +00:00
Jordan Rose
be12d86ddd Turn ClangModule into ClangModuleUnit.
Part of the FileUnit restructuring. A Clang module (whether from a framework
or a simple collection of headers) is now imported as a TranslationUnit
containing a single ClangModuleUnit.

One wrinkle in all this is that Swift very much wants to do searches on a
per-module basis, but Clang can only do lookups across the entire
TranslationUnit. Unless and until we get a better way to deal with this,
we're stuck with an inefficiency here. Previously, we used to hack around
this by ignoring the "per-module" bit and only performing one lookup into
all Clang modules, but that's not actually correct with respect to visibility.

Now, we're just taking the filtering hit for looking up a particular name,
and caching the results when we look up everything (for code completion).
This isn't ideal, but it doesn't seem to be costing too much in performance,
at least not right now, and it means we can get visibility correct.

In the future, it might make sense to include a ClangModuleUnit alongside a
SerializedASTFile for adapter modules, rather than having two separate
modules with the same name. I haven't really thought through this yet, though.

Swift SVN r10834
2013-12-05 01:51:11 +00:00
Jordan Rose
eede5ec4f9 Begin refactoring for mixed file kinds within a single module.
The goal of this series of commits is to allow the main module to consist
of both source files and AST files, where the AST files represent files
that were already built and don't need to be rebuilt, or of Swift source
files and imported Clang headers that share a module (because they are in
the same target).

Currently modules are divided into different kinds, and that defines how
decls are looked up, how imports are managed, etc. In order to achieve the
goal above, that polymorphism should be pushed down to the individual units
within a module, so that instead of TranslationUnit, BuiltinModule,
SerializedModule, and ClangModule, we have SourceFile, BuiltinUnit,
SerializedFile, and ClangUnit. (Better names welcome.) At that point we can
hopefully collapse TranslationUnit into Module and make Module non-polymorphic.

This commit makes SourceFile the subclass of an abstract FileUnit, and
makes TranslationUnit hold an array of FileUnits instead of SourceFiles.
To demonstrate that this is actually working, the Builtin module has also
been converted to FileUnit: it is now a TranslationUnit containing a single
BuiltinUnit.

Swift SVN r10830
2013-12-05 01:51:03 +00:00
John McCall
007d3974d6 Use a proper mangling to try to share reabstraction thunks.
Swift SVN r10764
2013-12-03 23:23:52 +00:00
Adrian Prantl
41e92af7ae Mangler: Add a DWARF-only mangling for type aliases that includes the
decl context of the type alias.
This implements <rdar://problem/15290346> "typealias sugar needs to be
mangled into debug info mangled type names".

Swift SVN r10749
2013-12-03 17:15:18 +00:00
Dave Zarzycki
8bd3582d3e 15242776 stdlib: rename Slice to Array
The "HArray" name is temporary.

Swift SVN r10707
2013-12-01 08:16:30 +00:00
Adrian Prantl
4fc5c9637b Mangler: Eliminate an ambiguity in the mangling of contexts.
<rdar://problem/15444866> Mangling is ambiguous -- may want prefix for functions

Swift SVN r10669
2013-11-23 00:56:16 +00:00
John McCall
b1bbbac19b Correct the mangling of SIL results to include the
ownership convention.

Swift SVN r10598
2013-11-20 18:05:05 +00:00