Commit Graph

52 Commits

Author SHA1 Message Date
Dmitri Gribenko
7235595264 Merge pull request #1108 from tinysun212/porting-to-cygwin
Porting to cygwin
2016-02-22 18:53:30 -08:00
Erik Eckstein
27929cba2a Support for mangling of generic specializations with different reabstraction.
This will be needed when the generic specializer will be able to change indirect arguments/results to direct arguments/results.
2016-02-22 13:58:10 -08:00
Han Sangjin
e06c7136cb Porting to Cygwin. rebased and squashed 2016-02-22 13:20:21 +09:00
Nadav Rotem
1ea38dd3e4 De-indent the switch cases (that Jordan noticed) 2016-01-08 17:24:48 -08:00
practicalswift
31ff35e1dd Use 80 column headers consistently. 2016-01-04 01:35:02 +01:00
Zach Panzarino
e3a4147ac9 Update copyright date 2015-12-31 23:28:40 +00:00
Nadav Rotem
bfb1f9a781 [Mangler] Refactor the mangling of OperatorKind into a helper function. NFC. 2015-12-29 14:21:35 -08:00
John McCall
8f30faa4c1 Include access functions for the metadata and witness tables
of associated types in protocol witness tables.

We use the global access functions when the result isn't
dependent, and a simple accessor when the result can be cheaply
recovered from the conforming metadata.  Otherwise, we add a
cache slot to a private section of the witness table, forcing
an instantiation per conformance.  Like generic type metadata,
concrete instantiations of generic conformances are memoized.

There's a fair amount of code in this patch that can't be
dynamically tested at the moment because of the widespread
reliance on recursive expansion of archetypes / dependent
types.  That's something we're now theoretically in a position
to change, and as we do so, we'll test more of this code.

This speculatively re-applies 7576a91009,
i.e. reverts commit 11ab3d537f.
We have not been able to duplicate the build failure in
independent testing; it might have been spurious or unrelated.
2015-12-29 12:14:40 -08:00
Dmitri Gribenko
11ab3d537f Revert "Include access functions for the metadata and witness tables"
This reverts commit 7576a91009.
It broke the testsuite for swift-corelibs-foundation.
2015-12-25 19:17:50 +02:00
John McCall
7576a91009 Include access functions for the metadata and witness tables
of associated types in protocol witness tables.

We use the global access functions when the result isn't
dependent, and a simple accessor when the result can be cheaply
recovered from the conforming metadata.  Otherwise, we add a
cache slot to a private section of the witness table, forcing
an instantiation per conformance.  Like generic type metadata,
concrete instantiations of generic conformances are memoized.

There's a fair amount of code in this patch that can't be
dynamically tested at the moment because of the widespread
reliance on recursive expansion of archetypes / dependent
types.  That's something we're now theoretically in a position
to change, and as we do so, we'll test more of this code.

This reverts commit 6528ec2887, i.e.
it reapplies b1e3120a28, with a fix
to unbreak release builds.
2015-12-24 20:21:17 -08:00
Sean Callanan
6528ec2887 Revert "Include access functions for the metadata and witness tables"
This reverts commit b1e3120a28.

Reverting because this patch uses WitnessTableBuilder::PI in NDEBUG code.
That field only exists when NDEBUG is not defined, but now NextCacheIndex, a
field that exists regardless, is being updated based on information from PI.

This problem means that Release builds do not work.
2015-12-23 15:42:10 -08:00
John McCall
b1e3120a28 Include access functions for the metadata and witness tables
of associated types in protocol witness tables.

We use the global access functions when the result isn't
dependent, and a simple accessor when the result can be cheaply
recovered from the conforming metadata.  Otherwise, we add a
cache slot to a private section of the witness table, forcing
an instantiation per conformance.  Like generic type metadata,
concrete instantiations of generic conformances are memoized.

There's a fair amount of code in this patch that can't be
dynamically tested at the moment because of the widespread
reliance on recursive expansion of archetypes / dependent
types.  That's something we're now theoretically in a position
to change, and as we do so, we'll test more of this code.
2015-12-23 00:37:24 -08:00
Mark Lacey
606356c7ad Change SIL box mangling prefix to Xb.
Now that we start with 'X', we can use 'b' for box.

Suggested by @jrose-apple.
2015-12-16 20:02:51 -08:00
Mark Lacey
514db32993 Change the mangling prefix for SIL boxes to 'XH'.
Use 'XH' rather than 'H' for SIL box types to keep SIL-specific concepts
under 'X' rather than claiming more of the top-level mangling namespace.

Suggested by @jckarter.
2015-12-16 16:47:14 -08:00
Mark Lacey
ae81a44ab3 Mangling and demangling support for SIL @box.
The SIL optimizer's closure specialization pass clones functions that
take closures as arguments and generates a new function with a direct
call to the closure function. The cloned function has new arguments
added for the values that are captured by the closure.

In the cases where the closure takes a @box argument, we were hitting an
assert attempting to mangle the name of the newly generated function,
since it now has a @box argument as a parameter. We don't normally
expect @box arguments during mangling because they do not exist prior to
SILGen, but since we generate new manglings throughout the optimizer we
need to be able to mangle (and demangle) these types.

Fixes rdar://problem/23893290.
2015-12-16 15:41:17 -08:00
Joe Groff
e55a3e1538 AllocBoxToStack: Update for box-only captures.
Change the logic to handle transforming @box T parameters into @inout_aliased T indirect parameters, instead of just dead-stripping boxes.
2015-12-08 14:35:48 -08:00
Joe Groff
172aee7f51 CapturePromotion: Update to handle lone box arguments.
Match the new SILGen pattern, where only the box parameter is partially applied to the closure, and the address of the value is projected on the callee side.
2015-12-08 14:35:47 -08:00
Joe Groff
86fab4a8f7 Demangler/Remangler: Purge iostreams. 2015-11-16 13:05:19 -08:00
Slava Pestov
21e01730f4 Revert "Don't need to mangle @nonobjc, NFC"
This reverts r32940. In reality this is not dead code, because
foreign to native thunks have the _TTO mangling. We need better
tests, which I will add in an upcoming commit.

Swift SVN r32945
2015-10-28 18:39:54 +00:00
Slava Pestov
a92ffea04c Don't need to mangle @nonobjc, NFC
Swift SVN r32940
2015-10-28 18:28:56 +00:00
Joe Groff
2368ce774b Remove self types from mangling by default.
And include some supplementary mangling changes:

- Give the first generic param (depth=0, index=0) a single character mangling. Even after removing the self type from method declaration types, 'Self' still shows up very frequently in protocol requirement signatures.
- Fix the mangling of generic parameter counts to elide the count when there's only one parameter at the starting depth of the mangling.

Together these carve another 154KB out of a debug standard library. There's some awkwardness in demangled strings that I'll clean up in subsequent commits; since decl types now only mangle the number of generic params at their own depth, it's context-dependent what depths those represent, which we get wrong now. Currying markers are also wrong, but since free function currying is going away, we can mangle the partial application thunks in different ways.

Swift SVN r32896
2015-10-26 22:05:20 +00:00
Joe Groff
9ffa0b218e Add demangler support for protocol descriptor symbols.
Swift SVN r32791
2015-10-21 17:44:09 +00:00
Joe Groff
7e119d0d53 Optimize the mangling of associated types in generic signatures.
Canonical dependent member types are always based from a generic parameter, so we can use a more optimal mangling that assumes this. We can also introduce substitutions for AssociatedTypeDecls, and when a generic parameter in a signature is constrained by a single protocol, we can leave that protocol qualification out of the unsubstituted associated type mangling. These optimizations together shrink the standard library by 117KB, and bring the length of the longest Swift symbol in the stdlib down from 578 to 334 characters, shorter than the longest C++ symbol in the stdlib.

Swift SVN r32786
2015-10-20 17:52:07 +00:00
Joe Groff
b77ea5e5ae Mangle the generic signature of a constrained extension after the containing module.
A microoptimization; since the module is likely to come up often in the subsequent mangling, we want to make it more likely to get the coveted S_ substitution.

Swift SVN r32784
2015-10-20 17:51:51 +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
Joe Groff
6e31ea5c08 Introduce standard substitutions for Unsafe*Pointer.
Together, UnsafePointer, UnsafeMutablePointer, UnsafeBufferPointer, and UnsafeMutableBufferPointer appear in standard library manglings over 1000 times, and they're fairly long names. Giving them standard substitutions shrinks the stdlib by 44KB.

Swift SVN r32410
2015-10-02 22:39:48 +00:00
Joe Groff
0cd5aa8c7c Change mangling for the Swift module from 'Ss' to 's'.
'Ss' appears in manglings tens of thousands of times in the standard library and is also incredibly frequent in other modules. This alone is enough to shrink the standard library by 59KB.

Swift SVN r32409
2015-10-02 22:39:44 +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
cb2c6a6d08 Demangle 'So' as '__ObjC' rather than 'ObjectiveC'.
And similarly 'SC' as '__C' rather than 'C'.

There's a real module named 'ObjectiveC', and imported decls are not
all in it.

Swift SVN r31225
2015-08-13 21:22:02 +00:00
Slava Pestov
cdd5a4121c IRGen: Generate value witnesses to get enum tag and project payload
These will be used for reflection, and eventually to speed up generic
operations on single payload enums as well.

Progress on <rdar://problem/21739870>.

Swift SVN r30214
2015-07-15 06:03:18 +00:00
Michael Gottesman
7ac6831bc6 [func-sig-opts] Eliminate dead arguments that are dead besides an @owned release.
This enables dead argument elimination to be paired with @owned -> @guaranteed
optimization. It has the additional advantage of allowing us to potentially
eliminate additional retains, releases since the fact that the use is dead
implies that the lifetime of the value no longer needs to be live across the
function call.

Since dead argument elimination can be composed with @owned -> @guaranteed, I
had to modify the mangler, remangler, demangler, to be able to handle a mangling
that combines the two.

I just saw noise in the perf test suite.

rdar://21114206

Swift SVN r29966
2015-07-08 06:26:25 +00:00
Joe Groff
7388b56035 Mangler: Include the error result of SILFunctionTypes in their mangling.
Fixes a mangling collision when e.g. reabstraction thunks for T -> U and T throws -> U are needed in the same module.

Swift SVN r29362
2015-06-10 20:27:24 +00:00
Joe Groff
7cb6fa320a AST: Mangle the generic params of constrained extensions.
Constrained and protocol extensions should always include the extension context in their mangling, since they are never equivalent to definitions in the original type context. Have them use the extension mangling, and include the generic signature of the extension in its mangling, which is necessary to disambiguate properties and other definitions that are defined with the same name and type in differently constrained extensions. Fixes rdar://problem/21027215.

Swift SVN r29209
2015-06-01 21:25:54 +00:00
John McCall
30149ca3fc Fix some demangling bugs with curried and throwing functions.
As part of this, I've made the demangler base the colon-vs.-not
decision on the entity kind instead of assuming that anything
with a function type must be a function.  It also looks through
new-style generics when it didn't before.

Swift SVN r28814
2015-05-20 01:56:18 +00:00
Joe Groff
c8078cbcdb Demangle: Tweak how dependent types are demangled to make them look more like archetypes.
Share the logic we use to map archetype depth-index pairs to friendly unique names like 'A', 'B', so that demangle generic signatures are still somewhat readable, and so that archetype references into outer contexts with interface type manglings still make sense. Change the remangler to mangle archetypes and dependent generic params using nested index nodes instead of trying to parse the depth and index from the arbitrary names we give them.

Swift SVN r28343
2015-05-08 23:57:25 +00:00
Joe Groff
9f8fd4e43c AST: Compress the mangling for generic signatures a bit.
Single generic parameters are common, as are a lack of requirements, so tweak things so that generic parameter counts are mangled as (count - 1), with a special mangling for zero, and give a single generic parameter at depth zero the empty-string mangling. Most requirements are protocol constraints, so use a better mangling for them that doesn't require the 'P..._' wrapping of the general type mangling. On the other hand, dependent member types ought to mangle in the protocol of the associated type, which adds some length, but isn't too bad since the protocol will almost definitely have a substitution introduced by a preceding protocol constraint.

Swift SVN r28296
2015-05-07 22:26:34 +00:00
Joe Groff
3f38d75006 SILGen: Currying of 'super.method' calls.
Keep track of a second set of "direct method reference" curry thunks that don't end in a dynamic dispatch in order to properly implement a partial application such as 'let foo = super.foo'. Fixes rdar://problem/20598526.

Swift SVN r27538
2015-04-21 22:56:03 +00:00
Joe Groff
c0a2994564 AST: Start printing function types with @convention instead of old attributes.
And update tests to match.

Swift SVN r27262
2015-04-13 22:51:34 +00:00
Joe Pamer
eee40fc53f Add basic parsing, sema and mangling support for throwing function types. Next up, metadata and serialization support, as well as more tests.
Swift SVN r26767
2015-03-31 18:55:19 +00:00
Michael Gottesman
3c2216b115 [+0 self] Add the deallocating parameter convention.
The deallocating parameter convention is a new convention put on a
non-trivial parameter if the caller function guarantees to the callee
that the parameter has the deallocating bit set in its object header.

This means that retains and releases do not need to be emitted on these
parameters even though they are non-trivial. This helps to solve a bug
in +0 self and makes it trivial for the optimizer to perform
optimizations based on this property.

It is not emitted yet by SILGen and will only be put on the self
argument of Deallocator functions.

Swift SVN r26179
2015-03-16 07:51:11 +00:00
Joe Groff
7b6c41055f Add mangling for C function pointer types.
Swift SVN r25498
2015-02-24 04:46:07 +00:00
Joe Groff
0b1e8ec6ab Remangler: Properly handle "static" as a context node.
Should bring the test/Demangle/remangle.swift test case back online.

Swift SVN r25120
2015-02-10 05:51:36 +00:00
Joe Groff
63463f54ac SIL: Mangle the static-ness of declarations.
This lets us disambiguate the symbols for static and instance properties, and enables us to eventually leave the useless "self" type mangling out of method symbols. Fixes rdar://19012022 and dupes thereof, including crasher #1341.

Swift SVN r25111
2015-02-10 02:37:35 +00:00
Joe Groff
a449948275 SILGen: Emit vtable thunks to handle optional variance.
If a subclass overrides methods with variance in the optionality of non-class-type members, emit a thunk to handle wrapping more optional parameters or results and force-unwrapping any IUO parameters made non-optional in the derived. For this to be useful, we need IRGen to finally pay attention to SILVTables, but this is a step on the way to fixing rdar://problem/19321484.

Swift SVN r24705
2015-01-24 05:21:26 +00:00
John McCall
a0d3214e4c Test that the remangler round-trips successfully.
To get this to work, delay some "cleanup" work in the
demangler.  For example, we now preserve in the tree
whether something was mangled as an allocating
initializer, and we only special-case the class vs.
non-class cases in the pretty printer.

Also fixes a number of remangling bugs, of course.

Swift SVN r24534
2015-01-19 23:12:58 +00:00