Commit Graph

779 Commits

Author SHA1 Message Date
eeckstein
719c8ffc45 Merge pull request #9046 from greglutz/SR-4683
Fix for SR-4683
2017-05-02 08:32:17 -07:00
Greg Lutz
ed483362e6 Addition of fix to test/SILGen/constrained_extensions.swift to pull request #9046 2017-05-01 22:04:26 -07:00
Slava Pestov
4fd870b81d AST: Change ExistentialLayout::requiresClass from a field to a method
We need to compute it lazily to avoid calling
ProtocolDecl::requiresClass() before the protocol's
inheritance clause has been type checked.
2017-05-01 15:49:03 -07:00
Bob Wilson
84d1630727 Merge pull request #9142 from shajrawi/loadable_by_addr_split
Code Size: Pass large loadable types by address instead of by value - Updated Version
2017-05-01 12:56:38 -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
Erik Eckstein
ae49b6939b Mangling: fix mangling of functions with a single empty tuple argument
For example:
	func testit(_ x: ()) -> Int
2017-04-28 16:51:34 -07:00
practicalswift
ff827e0455 [gardening] Fix recently introduced typos 2017-04-25 21:03:44 +02: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
595e0e4ede Merge branch 'master' into keypaths 2017-04-19 18:38:24 -07:00
Doug Gregor
ebdd56a1f0 [AST] Eliminate the "interface type" from protocol conformances.
We don't need this notion.
2017-04-18 17:15:15 -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
Jordan Rose
6c2e1b94c6 [Mangler] Handle initializer contexts with no associated variable.
I /think/ this can only come up in invalid code like

    class Outer {
      let _ = { class Inner {} }
    }

but we still try to generate USRs for this. Just use the enclosing
context as the current context so that we still generate /some/ valid
mangling.
2017-04-17 11:31:14 -07:00
Jordan Rose
3b07eda6aa [Mangler] Use '_' to represent nameless entities.
This can show up when trying to generate USRs for a document with
errors in it. This isn't a great answer because the names it generates
aren't unique (there may be more than one nameless entity with the
same type), but it at least generates valid mangled names.

When generating mangled names for purposes other than USRs, nameless
entities are now checked for by an assertion.
2017-04-17 11:31:11 -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
Slava Pestov
f8f8dca164 Mangler: Remove a bit of dead code from recent refactoring 2017-04-13 13:45:54 -07:00
Slava Pestov
b5ae8c4de6 AST: Add mangling for class-constrained existentials 2017-04-12 00:07:29 -07:00
practicalswift
00ba5dc248 [gardening] Fix typos 2017-04-02 16:23:45 +02:00
Erik Eckstein
069cd57089 Don't use substiutions when mangling ObjC runtime class names.
This caused a problem for classes which had the same name as the containing module.

SR-4374, rdar://problem/31272389
2017-03-30 10:24:29 -07:00
adrian-prantl
b433e5339e Merge pull request #8344 from adrian-prantl/31253373
Debugger type mangling: Pass GenericEnvironment separate from DeclContext
2017-03-27 10:13:14 -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
Adrian Prantl
b872127b66 Debgger type mangling: Pass GenericEnvironment separate from DeclContext.
This fixes a crash while building the Swift standard library when
partial specializations are enabled.

Eventually we should get rid of needing the DeclContext in the mangled
typename at all, and this is one step towards that goal.

rdar://problem/31253373
2017-03-25 14:09:14 -07:00
Slava Pestov
344504e6c9 IDE: Fix USR mangling for unnamed subscript parameters
Fixes <https://bugs.swift.org/browse/SR-4286>.
2017-03-24 21:52:58 -07:00
Erik Eckstein
11f66f8ce3 Mangling: Make sure we have different names for function overloads with all args in a tuple.
For example:
public func test(_ a: Int, _ b: Int)
public func test(_ t: (Int, Int))

fixes rdar://problem/31211238
2017-03-24 17:07:56 -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
Slava Pestov
173947ed14 AST: Improve const-correctness of ASTMangler 2017-03-23 23:32:37 -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
Slava Pestov
a3a290eb60 Mangling: Fix bug in the logic for dropping same-type constraints
It's not correct to drop a constraint if one of the two types
structurally contains generic parameters at the method depth.
2017-03-21 00:15:18 -07:00
Erik Eckstein
977b5c05ad Mangling: add a verifier that checks if every mangled symbol can be demangled and remangled. 2017-03-20 16:12:23 -07:00
Erik Eckstein
d70bfc5de2 rename namespace NewMangling -> Mangle 2017-03-20 10:09:30 -07:00
Erik Eckstein
1625345b90 Remove the old mangler.
NFC
2017-03-17 16:10:36 -07:00
Erik Eckstein
761d6512fe SourceKit: switch to new mangling in ide::printDeclTypeUSR
This was still missing.
2017-03-16 19:57:16 -07:00
Nathan Hawes
2c4bee9935 Merge pull request #8094 from nathawes/rdar31039915-index-local-params
[indexer] Index parameter definitions with a distinct external argument label too (but not their refs)
2017-03-14 17:44:25 -07:00
Nathan Hawes
7b75cf792c [indexer] Index parameter definitions with a distinct external argument label too (but not their refs)
Parameter defs with a separate external argument label are marked with the 'Local' symbol property.
This ensures the indexer has enough information for clients to match up a function's argument labels with its child parameter definitions.
Resolves rdar://problem/31039915.
2017-03-14 16:12:48 -07:00
Alex Hoppen
dd1c661c16 Merge pull request #8015 from ahoppen/isOperator-gardening
[Gardening] Change calls of getName().isOperator() to isOperator()
2017-03-10 21:10:33 +00:00
Alex Hoppen
1b7055db5a [Gardening] Change calls of getName().isOperator() to isOperator() 2017-03-10 09:06:20 +00: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
Slava Pestov
df81e51f36 AST: Add TypeBase::getRootGenericParam() utility method 2017-03-08 13:54:29 -08:00
Erik Eckstein
a04a29af4f mangling: efficient mangling of repeated substitutions
Instead of appending a character for each substitution, we now prefix the substitution with the repeat count, e.g.
AbbbbB -> A5B

The same is done for known-type substitutions, e.g.
SiSiSi -> S3i

This significantly shrinks mangled names which contain large lists of the same type, like
  func foo(_ x: (Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int))

rdar://problem/30707433
2017-03-05 17:41:43 -08:00
Erik Eckstein
b9c9ec0305 mangling: use meta programming for known-type substitutions
It’s better to have a single definition of known types which is then used in the mangler, demangler and remangler.

NFC
2017-03-05 17:40:46 -08:00
Erik Eckstein
fcd79c044d Mangling: consider bound generic types for substitutions
This shrinks the name length if the same bound generic type is used multiple times, like: func foo(_ x: [Int], _ y: [Int])
2017-03-05 17:40:07 -08:00
Slava Pestov
8407e11f9c AST: Fix mangling in preparation for generic subscripts
Subscripts in generic context will soon have a
GenericFunctionType, so get ready to handle that.
2017-02-21 23:52:12 -08:00
Slava Pestov
33a8ce6e7b AST: Canonicalize types with respect to generic signature when mangling
In the following example, the two declarations should have
the same mangled type:

protocol P {
  associatedtype P
}

func f1<T : P>(_: T) -> T.P where T.P == Int {}
func f2<T : P>(_: T) -> Int where T.P == Int {}

To ensure this is the case, canonicalize the entire
GenericFunctionType before taking it apart, instead of
canonicalizing structural components of it.
2017-02-20 16:41:37 -08:00
Erik Eckstein
8a6a9461d3 Only mangle non-private top-level classes and protocol with the old-style for the ObjC metadata.
Only those types can be de-mangled by the ObjC runtime anyway.
Also move this mangling logic into the ASTMangler class. This avoids keeping the old mangler around just for that purpose.
2017-02-16 18:20:05 -08:00
Slava Pestov
b8fd9e7259 AST: Move the well-formedness check from mangling to GenericSignature constructor 2017-02-07 15:30:39 -08:00
Erik Eckstein
e6f2e7bc88 Mangling: add a few utility functions in the new mangler and demangler which will be used by reflection mangling 2017-02-07 08:36:21 -08:00
Andrew Trick
1abeddcc5d [SILType] SILFunctionConventions API.
Separate formal lowered types from SIL types.
The SIL type of an argument will depend on the SIL module's conventions.
The module conventions are determined by the SIL stage and LangOpts.

Almost NFC, but specialized manglings are broken incidentally as a result of
fixes to the way passes handle book-keeping of aruments. The mangler is fixed in
the subsequent commit.

Otherwise, NFC is intended, but quite possible do to rewriting the logic in many
places.
2017-01-26 15:35:48 -08:00