Commit Graph

402 Commits

Author SHA1 Message Date
Matt Gallagher
468acd3b38 Fixed faulty boolean logic
This is a trivial logic error. The "abort" condition would be followed only if `c == 0` with other clauses having no effect.
2017-11-16 23:00:34 +11:00
Joe Shajrawi
5aff0891b7 Code size: copy_addr outline part 2 - Support Archetypes 2017-11-15 15:26:44 -08:00
John McCall
7743be30f6 Add a "token" type to SIL to allow dependencies to be expressed without
allowing abstraction.
2017-11-13 04:03:21 -05:00
Slava Pestov
78ad6c4577 AST: New mangling for method dispatch thunks 2017-11-11 16:31:53 -08:00
Joe Shajrawi
f4db36426c Code Size: Outline copy addr instruction 2017-10-31 17:03:48 -07:00
Andrew Trick
d369aa4070 Support @noescape SIL function types. (#12420)
Support for @noescape SILFunctionTypes.

These are the underlying SIL changes necessary to implement the new
closure capture ABI.

Note: This includes a change to function name mangling that
primarily affects reabstraction thunks.

The new ABI will allow stack allocation of non-escaping closures as a
simple optimization.

The new ABI, and the stack allocation optimization, also require
closure context to be @guaranteed. That will be implemented as the
next step.

Many SIL passes pattern match partial_apply sequences. These all
needed to be fixed to handle the convert_function that SILGen now
emits. The conversion is now needed whenever a function declaration,
which has an escaping type, is passed into a @NoEscape argument.

In addition to supporting new SIL patterns, some optimizations like
inlining and SIL combine are now stronger which could perturb some
benchmark results.

These underlying SIL changes should be merged now to avoid conflicting
with other work. Minor benchmark discrepancies can be investigated as part of
the stack-allocation work.

* Add a noescape attribute to SILFunctionType.

And set this attribute correctly when lowering formal function types to SILFunctionTypes based on @escaping.

This will allow stack allocation of closures, and unblock a related ABI change.

* Flip the polarity on @noescape on SILFunctionType and clarify that
we don't default it.

* Emit withoutActuallyEscaping using a convert_function instruction.

It might be better to use a specialized instruction here, but I'll leave that up to Andy.

Andy: And I'll leave that to Arnold who is implementing SIL support for guaranteed ownership of thick function types.

* Fix SILGen and SIL Parsing.

* Fix the LoadableByAddress pass.

* Fix ClosureSpecializer.

* Fix performance inliner constant propagation.

* Fix the PartialApplyCombiner.

* Adjust SILFunctionType for thunks.

* Add mangling for @noescape/@escaping.

* Fix test cases for @noescape attribute, mangling, convert_function, etc.

* Fix exclusivity test cases.

* Fix AccessEnforcement.

* Fix SILCombine of convert_function -> apply.

* Fix ObjC bridging thunks.

* Various MandatoryInlining fixes.

* Fix SILCombine optimizeApplyOfConvertFunction.

* Fix more test cases after merging (again).

* Fix ClosureSpecializer. Hande convert_function cloning.

Be conservative when combining convert_function. Most of our code doesn't know
how to deal with function type mismatches yet.

* Fix MandatoryInlining.

Be conservative with function conversion. The inliner does not yet know how to
cast arguments or convert between throwing forms.

* Fix PartialApplyCombiner.
2017-10-17 13:07:25 -07:00
Erik Eckstein
e21b9124ee Demangler: fix demangling and remangling of associated type paths.
fixes SR-6138
2017-10-16 17:30:34 -07:00
Doug Gregor
6e6b6b9837 [Mangler] Only mangle new requirements for constrained extensions.
Rather than mangling the complete generic signature of a constrained
extension, only mangle the requirements not already satisfied by the
nominal type. For example, given:

    extension Dictionary where Value: Equatable {
      // OLD: _T0s10DictionaryV2t3s8HashableRzs9EquatableR_r0_lE3baryyF
      // NEW: _T0s10DictionaryV2t3s9EquatableR_rlE3baryyF
      public func bar() { }
   }

In the existing mangling, we mangle the `Key: Hashable` requirement that’s
part of the generic signature. With this change, we only mangle the new
requirement (`Value: Equatable`).

This is a win for constrained extensions *except* in the case of a
constrained extension of a nominal type with a single, unconstrained
generic parameter:

    extension Array where Element: Equatable {
      // OLD: _T0Sa2t3s9EquatableRzlE3baryyF
      // NEW would be: _T0Sa2t3s9EquatableRzrlE3baryyF
      public func bar() { }
    }

Check explicily for this shortcut mangling and fall back to the old
path, so this change is a strict improvement.
2017-10-11 19:23:58 -07:00
Joe Groff
78d75428d6 SILGen: Lower key path subscript indexes.
And fill out SIL support for parsing, printing, and serializing key path
patterns with captured indexes.
2017-09-15 10:00:32 -07:00
Alex Hoppen
1c7e289b96 [Mangling] Adjust subscript mangling to not include "subscript"
Change the mangling of accessors to have a variable or subscript node
as their only child node, while subscript nodes no longer contain a decl
name.
2017-09-10 19:44:07 +02:00
Arnold Schwaighofer
48bd2bba76 Mangling changes for outlined Objective-C method calls
rdar://33387700
2017-09-06 08:37:30 -07:00
Erik Eckstein
c1e98b9df2 mangling: Add mangling for outlined global variables 2017-08-23 09:15:01 -07:00
Robert Widmann
4babbe95e1 Push __shared into the mangling and down thru to codegen
This does not lower to @guaranteed as of yet.
2017-07-23 21:47:25 -07:00
Erik Eckstein
08ccd39362 Demangler: refactoring: use qualified declarations for some utility functions
NFC
2017-06-28 13:59:00 -07:00
Erik Eckstein
ecd177fa17 Demangler: handle suffixes in the form '.<n>'.
Demangle such suffixes as "unmangled suffix"
IRGen still uses '.<n>' to disambiguate partial apply thunks and outlined copy functions.

rdar://problem/32934962
2017-06-26 15:19:20 -07:00
Erik Eckstein
79c522a49d demangler: Support the future final mangling prefix $S
As it’s not clear if we will need underscores, the demangler accepts $S and _$S.
Note that a double underscore is handled by the demangler client.

rdar://problem/32251811
2017-06-26 11:32:26 -07:00
Jordan Rose
c1c4f5243b [Mangling] Include private discriminators in constructor manglings. (#9880)
Previously, two constructors with the same full name and argument
types would get identical manglings even if they were declared
'private' or 'fileprivate' in different files. This would lead to
symbol collisions in whole-module builds. Add a new mangling node for
private discriminators on base-name-less decls to make this unique.

This still doesn't fix the existing issue with private members, named
or not, conflicting when they're in the /same/ file, but since Swift 4
makes those members visible to one another (SE-0169) that's only an
issue in Swift 3 mode anyway, and as such probably won't get fixed at
all.

rdar://problem/27758199
2017-06-01 16:42:17 -07:00
Erik Eckstein
6a478caf7d demangling: Drop the support of "unmangled suffix"
Either the demangling completely succeeds or it fails. Don't demangle to something like: [...] with unmangled suffix "..."

This avoids getting really stupid demangled names for symbols which are actually not swift symbols.
2017-05-24 17:00:20 -07:00
Erik Eckstein
d342041420 Mangling: use ‘Tm’ mangling for merged functions
Previously merged functions just got the name with a “_merged” suffix
2017-05-24 17:00:16 -07:00
Erik Eckstein
cb4564ecd0 Demangler: replace an assert with a bail-condition.
The assert condition can be false for a malformed symbol, like _T0s30ReversedRandomAccessCollectionVyxGTfq3nnpf_nTfq1cn_nTfq4x_n

rdar://problem/32359287
2017-05-23 15:58:51 -07:00
Erik Eckstein
e8ce388651 Demangler: fix a hang in case a malformed symbol ends with an 'A<digit>'
For example _T0A8

rdar://problem/32359287
2017-05-23 13:53:24 -07:00
Erik Eckstein
ff892f9e19 Demangler: don’t crash if demangling a malformed KeyPath[GS]etterThunkHelper
rdar://problem/32333373
2017-05-22 16:50:26 -07:00
Erik Eckstein
4efdcebf80 Demangler: make the demangler more tolerant with malformed symbols.
Instead of crashing it just should not demangle malformed symbols.

rdar://problem/32113006
2017-05-16 12:28:32 -07:00
Joe Groff
69a7ef6e2d Revert "SILGen: Tweak key path computed property lowering to produce a consistent runtime-callable ABI."
This reverts commit 4522cd09aa. This was a failed approach I shouldn't have committed. Fixes rdar://problem/32201589.
2017-05-15 16:10:55 -07:00
Jordan Rose
c8d3506e55 Revert "[Mangling] Uniformly use "So" for imported decls." (#9233)
This reverts commit 25985cb764. For now,
we're trying to avoid spurious non-structural changes to the mangling,
so that the /old/ mangling doesn't appear to change. That doesn't mean
no changes at all, but we can save this one for later.
2017-05-03 16:13:29 -07:00
Joe Shajrawi
0d0cac357a retain_value_addr and release_value_addr SIL instructions: take as an input an address, load the value inside it and call retain_value and release_value respectively 2017-04-30 10:23:55 -07:00
Joe Shajrawi
d17258cac7 @in_constant calling convention - part of passing large loadable types by address 2017-04-30 10:13:02 -07:00
Jordan Rose
25985cb764 [Mangling] Uniformly use "So" for imported decls.
...and repurpose "SC" for (C)lang-importer-synthesized decls, instead
of just decls that are C-like instead of ObjC-like. (See next commits.)
2017-04-24 09:57:30 -07:00
Joe Groff
3d178be169 Merge pull request #8875 from jckarter/keypaths
Keypaths
2017-04-21 17:51:17 -07:00
practicalswift
431e5a1440 [gardening] Use consistent end of namespace comments 2017-04-20 13:47:10 +02:00
Joe Groff
595e0e4ede Merge branch 'master' into keypaths 2017-04-19 18:38:24 -07:00
Joe Groff
4522cd09aa SILGen: Tweak key path computed property lowering to produce a consistent runtime-callable ABI. 2017-04-18 11:44:39 -07:00
Jordan Rose
2d84981fc2 Improve the mangling of typealiases.
- Allow them to use substitutions.
- Consistently use 'a' as a mangling operator.
- For generic typealiases, include the alias as context for any generic
  parameters.

Typealiases don't show up in symbol names, which always refer to
canonical types, but they are mangled for debug info and for USRs
(unique identifiers used by SourceKit), so it's good to get this
right.
2017-04-17 11:31:15 -07:00
Jordan Rose
5de0a39f62 [Mangler] Verify USR manglings as well. 2017-04-17 11:31:15 -07:00
Joe Groff
ee66ff35c5 SILGen: Lower computed property key path components. 2017-04-14 17:13:38 -07:00
Jordan Rose
7c73ba5fe3 If a function has an error type, mangle it as '(Error) -> Error'.
This lets the mangling preserve the invariant that functions always
structurally have function types. Error types don't show up in mangled
names often anyway, but it can occur when you ask for the USR of a
function with an invalid type.
2017-04-14 17:02:54 -07:00
Slava Pestov
0d0dc207c0 AST: Mangling for primitive AnyObject
A protocol composition with an explicit 'AnyObject' member is
now mangled as <protocol list> 'Xl'. For subclass existentials,
I changed the mangling from <protocol list> <class> 'XE' to
<protocol list> <class> 'Xl'.

Not used for anything just yet.
2017-04-13 21:17:07 -07:00
Huon Wilson
22c9e20a9d [IRGen] Completely remove witness table offsets.
These are unused.
2017-04-13 11:44:01 -07:00
Slava Pestov
b5ae8c4de6 AST: Add mangling for class-constrained existentials 2017-04-12 00:07:29 -07:00
Erik Eckstein
3ee9c88166 Demangler: fix de- and re-mangling of constrained extensions
SR-4512
rdar://problem/31471429
2017-04-06 16:07:13 -07:00
Erik Eckstein
e427ded6c9 Mangling: refactoring: clean up tuple nodes
Replace VariadicTuple and NonVariadicTuple with a single Tuple node.
The variadic property is now part of the tuple element and not of the whole tuple.
2017-03-25 19:07:52 -07:00
Erik Eckstein
327017a65b Mangling: support mangling of varargs even if it's not the last argument.
Example:
func a(arr: Int..., n: String)

fixes SR-1076
2017-03-25 19:07:52 -07:00
Slava Pestov
e912f27944 AST/SILGen: New mangling for vtable thunks
Simply mangling the derived method is no longer sufficient. Now also
mangle the base method, so that eventually we handle this sort of
scenario:

class Base {
  // introduces: Base.method
  func method(_: Int, _: Int) {}
}

class First : Base {
  // overrides: Base.method
  // introduces: First.method
  override func method(_: Int?, _: Int) {}
}

class Second : First {
  // overrides: Base.method, First.method
  // introduces: Second.method
  override func method(_: Int?, _: Int?) {}
}

Here, the override of Base.method by Second.method and the
override of First.method by Second.method require distinct
manglings even though the derived method (Second.method) is
the same in both cases.

Note that while the new mangling is longer, vtable thunks are
always emitted with private linkage, so with the exception of
the standard library which is built with -sil-serialize-all
they will not affect the size of dylibs.

The standard library itself has very few classes so it doesn't
matter there either.

This patch doesn't actually add any support to introduce new
vtable entries for methods that override; this is coming up
next.
2017-03-23 23:40:52 -07:00
Roman Levenstein
e7503b1502 [mangling] Define a mangling for _Class and _NativeClass layout constraints
I forgot to define the mangling when I introduced these two new layout constraints.
2017-03-22 23:36:40 -07:00
Erik Eckstein
160d268991 mangling: Correctly demangle + remangle extensions of generic types.
fixes rdar://problem/31181011
2017-03-22 10:39:53 -07:00
Erik Eckstein
d70bfc5de2 rename namespace NewMangling -> Mangle 2017-03-20 10:09:30 -07:00
Erik Eckstein
2fbbef2fb4 Mangling: drop the support of mangling a function specialization argument which is an old-mangled function 2017-03-17 16:10:36 -07:00
Erik Eckstein
aa8cc0a539 demangler: fix a crash when trying to demangle a non-swift symbol
rdar://problem/30982254
2017-03-10 15:36:40 -08:00
Erik Eckstein
e463e69c33 demangler: Don’t emit an empty string with “with suffix ...” if the full name could not be demangled
Instead just emit the original name
2017-03-10 15:36:40 -08:00
Erik Eckstein
5e80555c9b demangler: put the demangler into a separate library
Previously it was part of swiftBasic.

The demangler library does not depend on llvm (except some header-only utilities like StringRef). Putting it into its own library makes sure that no llvm stuff will be linked into clients which use the demangler library.

This change also contains other refactoring, like moving demangler code into different files. This makes it easier to remove the old demangler from the runtime library when we switch to the new symbol mangling.

Also in this commit: remove some unused API functions from the demangler Context.

fixes rdar://problem/30503344
2017-03-09 13:42:43 -08:00